views:

49

answers:

1

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 ?

+2  A: 

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);
    }
}
Michael Baker
@Michael, it is possible to next find job list of this printer?
netmajor
The query is, SELECT * FROM Win32_PrintJob and pass "Name" to indexer.
Michael Baker
@Michael so Win32_PrintJob give me jobs from computer I use? But how to get jobs from specific printer? Something like use Win3Printer to get Network printers and next using Win32_PrintJob to get all jobs from specific printer... It is possible ?
netmajor
@netmajor. You should accept this answer and ask that one as another question. It would be useful to have both on SO as separate answers.
Preet Sangha