我们有一台打印服务器,上面有很多打印机。我们这样访问它们:
\\print-server-name\printer1
\\print-server-name\printer1_color
\\print-server-name\printer2
...等
我现在需要该服务器上所有打印机的列表。到目前为止,我只能在机器上找到本地安装的所有打印机。我在google搜索时发现了这一点,这只给了我当地的打印机以及:
PrintServer lps = new PrintServer();
PrintQueueCollection prQueue = lps.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Connections });
liServerPrinterNames = (from printer in prQueue select printer).ToList();
实际上我只需要字符串数组中服务器上所有打印机的名称,我甚至不需要对象进行交互,只需将所有打印机的名称作为字符串。那可能吗?怎么样?
提前感谢您的帮助!
答案 0 :(得分:0)
获取所有InstalledPrinters
foreach (string printer in PrinterSettings.InstalledPrinters)
使用WMI Windows Management Instrumentation
SelectQuery query = new SelectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher mos= new ManagementObjectSearcher(mos, query);
System.Management.ManagementObjectCollection moc= mos.Get();
foreach (ManagementObject Printers in moc )
Printers["Name"]; //GetPrinterName
}