0

I am retrieving the default print queues thanks to the help of this question. I am also able to determine the DefaultPrintQueue

But how does one properly determine what print queue in the list of print queues is equal to the DefaultPrintQueue?

I've tried:

var dq = LocalPrintServer.GetDefaultPrintQueue();
foreach(PrintQueue pq in pqcOnLocalServer)
{
    if(pq.Equals(dq))
    {
        System.Console.WriteLine("Found default"); 
    }
}

but the two objects obviously won't be the same. I would then assume I could compare properties of each PrintQueue with the default, but what properties should be used to determine, 100%, that the two PrintQueues are referring to the same PrintQueue?

Community
  • 1
  • 1
Kcvin
  • 5,073
  • 2
  • 32
  • 54

2 Answers2

0

Try and use the LocalPrintServer.DefaultPrintQueue property to get the default print queue and compare the PrintQueue.FullName. This negates the need to iterate through the LocalPrintServer PrintQueueCollection.

LocalPrintServer printServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue pq = printServer.DefaultPrintQueue;

PrintQueue dq = LocalPrintServer.GetDefaultPrintQueue();

if (dq != null && pq.FullName.Equals(dq.FullName))
{
   Console.WriteLine("Found default print Queue: {0}", dq.FullName);
}

If you still need to iterate through the LocalPrintServer PrintQueueCollection you can try the implementation below.

LocalPrintServer printServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);

PrintQueue dq = LocalPrintServer.GetDefaultPrintQueue();

foreach (PrintQueue pq in printServer.GetPrintQueues())
{
    if (dq != null && pq.FullName.Equals(dq.FullName))
    {
         Console.WriteLine("Found default print Queue: {0}", dq.FullName);
    }
}
Jamleck
  • 1,017
  • 7
  • 12
  • is there any chance you found documentation station `FullName` is a unique string; meaning no two Printer's will have the same `FullName`? What concerns me is the [documentation](http://msdn.microsoft.com/en-us/library/system.printing.printqueue.fullname(v=vs.110).aspx) stating, `this property's value is identical to Name`. This is the approach I have been using, just wanted to see if there is a better way. – Kcvin Jun 10 '14 at 12:12
  • I didn't find any documentation indicating if `FullName` is a unique string or not. I'll do some testing when I get a moment. I suspect it's not unique & you might need to use a combination of the `FullName`, driver name & port name. Are you able to tell me what problem you are trying to solve? Do you need to get a list printers installed from the user's perspective or are you managing remote print servers? Let me know. – Jamleck Jun 10 '14 at 14:47
  • I'm retrieving the local machines PrintQueues to eventually set/merge the print ticket. Basically I don't want the user to confuse two printers, or not know the difference between two. – Kcvin Jun 10 '14 at 15:24
0

This question might have done well on Expert Exchange, or Server Exchange. What I've found is that a print server will not allows printers on the server which have existing names already on the printer server. With that being said, a printer must have a unique name per server.

With that being said, a user must be careful to not only compare printer names to ensure that they are unique, but they must also compare the printer server that they are on. For example, when enumerating connected a printers. A computer could be connected to two print servers where there is a \\PRNTSRVR1\HQ_LaserJet01 and \\PRNTSRVR2\HQ_LaserJet01; so checking the connected server is important too.

Kcvin
  • 5,073
  • 2
  • 32
  • 54