1

I am using this code to check if my printer is in the 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. But my printer is always in the network.

public bool IsPrinterReady(string PrinterName)
{
    ManagementScope scope = new ManagementScope(@"\root\cimv2");
    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;
}

Please note that I always get the value as true for my following if statement

if(strPrinter.ToLower() == PrinterName.ToLower())

I just get varied values from

printer["PrinterStatus"].ToString()

Thanks in advance

Adarsh Ravi
  • 893
  • 1
  • 16
  • 39
  • http://stackoverflow.com/questions/1018001/is-there-a-net-way-to-enumerate-all-available-network-printers – Yanshof Oct 04 '15 at 09:06
  • @Yanshof I get the network printer always but for some reason I get the value for printer["PrinterStatus"] as 4 the first time and the second time I get 3 which is the value I am looking for. – Adarsh Ravi Oct 04 '15 at 09:22

0 Answers0