4

I have a problem that I need help with. For my current project I need to make a Batch Plot application. This application will have around ~2000 AutoCAD drawings that it will need to print.

The application needs 5 printers, 1 for each format, going from A4 to A0. No problems yet so far.

Now we all understand that we can not queue 2000 drawings simultaneously without some kind of trouble. I've did my research online and found methods to look at the current printer Queue. Using PrintServer and PrintQueue.

Here is where the problems begin. Firstly I am not able to find the network printers that I need. The printers are located on this network address: 192.168.0.14 (\vps01w2k8).

Following the guide from MSDN:

    PrintServer m_PrintServer = new PrintServer(@"\\vps01w2k8");
    PrintQueueCollection m_PrintQueueCollection = m_PrintServer.GetPrintQueues();

    foreach (PrintQueue queue in m_PrintQueueCollection)
    {
         cbPrinters.Items.Add(queue.Name.ToString());
    }

This does not give me any printers. Trying LocalPrintServer (or just PrintServer without any parameters passed into it). Gives me my local printers (obviously) and not my network printers.

My next step was to find a method to find all my installed printers which got me into using System.Drawing.Printing; instead of using System.Printing;.

    foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    {
         cbPrinters.Items.Add(printer.ToString());
    }

This simple code gives me all the printers I have, including the networked ones. However, now I am stuck between .NET 2.0 and 3.0 (and onward). The classes PrinterSettings and PrintServer/PrintQueue have no connection.

Lastly I tried to get access to the printer queues using the WMI approach. Querying the Win32_PrintJob which gave me results. Unfortunately these came along with 10 second lock-ups to retrieve these results.

I'm out of ideas. I'm either looking for a fix for the PrintServer to properly return my networked printers or any suggestions to do similar techniques for batch plotting with the PrinterSettings class.

Thanks in advance,

Jordy

Kaiwa
  • 171
  • 1
  • 6
  • are the network printers also 'connected' in windows? – aL3891 Jul 20 '11 at 14:39
  • Yes, they are active and can be used. – Kaiwa Jul 20 '11 at 18:57
  • i see, also, you mentioned that the msdn sample doesnt give you any printers, but isnt it that you dont get any printer queues? (m_PrintServer.GetPrintQueues() returns nothing) id guess this is some sort of secutiry problem.. is the program running under a diffrent account security context? (that is, is it running full trust?) – aL3891 Jul 20 '11 at 19:28
  • I don't actually use UAC. Fully turned off, so the account security is exactly the same. I tried connecting to the PrintServer using additional parameters for the specific PrintSystemDesiredAccess. I tried both UsePrinter (Lowest desired access I believe) and got nothing. I'm mainly thinking that it's something with security too though, but I have no ideas on how to actually get sufficient access to the printers. I can't specify a domain user if remember correctly...) – Kaiwa Jul 20 '11 at 21:08
  • Hm im out of ideas im affraid :/ You can look at the [Environment](http://msdn.microsoft.com/en-us/library/system.environment.aspx) class to get info on the current user and domain, just to confirm that the credentials are correct – aL3891 Jul 20 '11 at 21:26
  • Found my solutions this morning :) Thanks for you efforts! – Kaiwa Jul 21 '11 at 06:08

1 Answers1

13

Found it. When calling GetPrintQueues you have to pass in an array of EnumeratedPrintQueueTypes. It now returns both my local and network printers (all installed printers).

PrintServer m_PrintServer = new PrintServer();
PrintQueueCollection m_PrintQueueCollection = m_PrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
Kaiwa
  • 171
  • 1
  • 6