How can I uniquely identify a print queue on Windows even if the queue is renamed?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine

How can I uniquely and reliably identify a Windows print queue on a given server, including across print queue renames?

I want to handle cases like the following:
  • Jdoe creates Printer A
  • My program gathers information on Printer A at some point
  • Jdoe renames Printer A to Printer AA
  • My program gathers information on Printer AA again at some point

How can I tell that Printer A and Printer AA are the same printer (with the name changed)? This allows me to do things like determine that Document 1 printed to Printer A was sent to the same printer as Document 2 sent to Printer AA (after the rename).

I want to do this in C# supporting Windows XP/2003 and up.

Things Ive tried:

On Windows 8/Server 2012 it appears that I can do this via WMI looking at CIM_LogicalDevice->DeviceID, which seems to remain consistent across renames, but in earlier versions of the OS this property just contains the queue name and changes when the queue is renamed.

Ive also looked at the Win32_PnPEntity class (which doesnt contain printers pre Windows 8) and Win32_Printer class (which doesnt contain any sort of ID other than the name).

In the registry HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionPrintPrinters[printer name] has a QueueInstanceId field containing a GUID, but only in Windows 8/Server 2012. It is not present in earlier OSs.

The print spooler API and GDI print APIs both appear to identify queues by name, so I havent found anything useful there.


View the full article
 
Back
Top