尝试运行以下内容(此处为http://www.encodedna.com/2013/04/show-printers-using-wmi.htm)以获取网络打印机列表,但它只返回添加到我的计算机的打印机
System.Management.ManagementScope objMS = new System.Management.ManagementScope(ManagementPath.DefaultPath);
objMS.Connect();
SelectQuery objQuery = new SelectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher objMOS = new ManagementObjectSearcher(objMS, objQuery);
System.Management.ManagementObjectCollection objMOC = objMOS.Get();
foreach (ManagementObject Printers in objMOC)
{
if (Convert.ToBoolean(Printers["Local"])) // LOCAL PRINTERS.
{
Console.WriteLine("Local :- " + Printers["Name"]);
}
if (Convert.ToBoolean(Printers["Network"])) // ALL NETWORK PRINTERS.
{
Console.WriteLine("Network :- " + Printers["Name"]);
}
}
我可以在控制面板中查看/添加网络打印机。只是好奇为什么它没有显示出来。有什么想法吗?
谢谢!
答案 0 :(得分:0)
尝试:
foreach (string printerString in PrinterSettings.InstalledPrinters)
{
// do something
}