ManagementObjectSearcher select network printers?

て烟熏妆下的殇ゞ 提交于 2019-12-10 23:58:55

问题


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


来源:https://stackoverflow.com/questions/3264888/managementobjectsearcher-select-network-printers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!