Wednesday, October 20, 2010

Check Printer Status in C#

Assembly : System.Management;

     public bool CheckPrinterStatus()
        {

            ManagementScope scope = new ManagementScope(@"\root\cimv2");
            scope.Connect();

            // Select Printers from WMI Object Collections

            ManagementObjectSearcher PrinterCollection= new
            ManagementObjectSearcher("SELECT * FROM Win32_Printer");

            string printerName = "";

            foreach (ManagementObject printer in PrinterCollection.Get())
            {
                printerName = printer["Name"].ToString().ToLower();
                if (printerName.Equals(@"hp laserjet 1018"))
                {
                    MessageBox.Show("Printer = " + printer["Name"]);
                    if (printer["WorkOffline"].ToString()=="True")
                    {
                        // Printer is offline

                        MessageBox.Show("Printer is not Connected.");
                        return false;
                    }
                    else
                    {
                        // Printer is Online
                       MessageBox.Show("Printer is Connected.");
                        return true;
                    }
                }
            }
        }

No comments:

Post a Comment

Mat Table Angular

Mat Table in Angular Mat table is used to display data . its a material designed styled data-table . For using Material Table MatTableMo...