How to check if printer is in network?

public bool IsPrinterReady(string PrinterName)
{
 ManagementScope scope = new ManagementScope(@"rootcimv2");
 scope.Connect();
 ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Printer");

 string strPrinter = string.Empty;
 foreach(ManagementObject printer in searcher.Get())
 {
     strPrinter = printer["Name"].ToString();
     if(strPrinter.ToLower() == PrinterName.ToLower())
        return printer["PrinterStatus"].ToString().ToLower().Equals("3");
 }
 return false;
}

I am using the code to check if my printer is in network. When I hit the Print button the first time, it gives me not connected status. And when I hit it for the second time it prints successfully. And my printer is always in the network. Please help

Thanks in advance


Source: .net

Leave a Reply