ManagementObjectSearcher select network printers?

2019-07-15 11:31发布

I use :

ManagementObjectSearcher searcher = new 
    ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer"); 

to get printers but it find local printers.. It's possible to select network printers , by ip maybe ?

1条回答
神经病院院长
2楼-- · 2019-07-15 12:02

Pass "Network" to the object indexer of each item in your ManagementObjectCollection. If the printer is a network printer it will return true. Likewise you can pass "Local" to determine if the printer is local.

var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer");
var results = searcher.Get();

IList<ManagementBaseObject> printers = new List<ManagementBaseObject>();

foreach (var printer in results) {
    if ((bool)printer["Network"]) {
        printers.Add(printer);
    }
}
查看更多
登录 后发表回答