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 

 

posted @ 2013-05-06 11:08  John29  阅读(430)  评论(0编辑  收藏  举报