-
网上打了很多方法都无效,以下方法在WIN7pro中测试可用:
通过直接使用WMI来获取
using System.Management;
string query = string.Format("SELECT * from Win32_Printer "); var searcher = new ManagementObjectSearcher(query); var printers = searcher.Get(); foreach(var printer in printers) { Console.WriteLine(printer.Properties["Name"].Value); foreach(var property in printer.Properties) { Console.WriteLine(string.Format("\t{0}: {1}", property.Name, property.Value)); } Console.WriteLine(); }
如此可以得到许多信息,包括状态、联机、脱机以及错误其中 (bool)printer.Properties["WorkOffline"].Value 指示打印机是否脱机