ManagementObjectSearcher select network printers?

2019-07-15 11:18发布

问题:

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:

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);
    }
}