C# WMI 打印机
获取打印机列表
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Default: {0}", queryObj["Default"]);
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("DriverName: {0}", queryObj["DriverName"]);
}
设定默认打印机
ManagementObject classInstance =
new ManagementObject("root\\CIMV2",
"Win32_Printer.DeviceID='" + comboBox1.Text + "'",
null);
ManagementBaseObject outParams =
classInstance.InvokeMethod("SetDefaultPrinter", null, null);
//ReturnValue :0