How to retrieve a list of physical printers using WMI?
I'm trying to get a list of hardware printers attached to a windows XP machine by using WMI. What i'd like is not the same as getting the list from Win32_Printers since i'd only like to get printers that physically exist as boxes, getting rid of all the "printer noise" like "Send to OneNote Driver", "Microsoft Shared Fax Driver", "Microsoft XPS Document Writer", etc...
By using WMICodeCreator tool i found out that i can't rely on the Local/Network properties being true (as of now, my network printer tells me that its network property is false...) so i'd like to know if there is another way to get the correct information?
Bonus points if i can get the 开发者_运维知识库usb printers attached to the computer: the Win32_USBHub property doesn't really help here since i can't get the correct description of "Printing Support" :)
I know this is a really old post but I ran into the same requirements and figured I would post my end result for the next person to come along.
Dim oWMI, colPrinters, oItem, oPrinter
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colPrinters = oWMI.ExecQuery("Select * From Win32_Printer where PrintProcessor <> 'winprint'")
For Each oPrinter in colPrinters
If oPrinter.Attributes And 64 Then
Wscript.Echo oPrinter.Name
End If
Next
I think that just physical printer use the unidrv.dll
string query = "select * from Win32_PrinterDriver";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
Console.WriteLine(obj["Name"].ToString());
Console.WriteLine(obj["DriverPath"].ToString());
Console.WriteLine();
}
精彩评论