Using Management Objects to check Online Printers


I have used the Management class for the first time now and I find it very interesting.

First you have to add a reference System.Managemnt to the project.

using System.Management;

 

ManagementScope mgmtscope=new ManagementScope(@"\root\cimv2");

mgmtscope.Connect();

ManagementObjectSearcher objsearcher=new ManagementObjectSearcher("Select * from Win32_Printer");

foreach(ManagementObject printer in objsearcher.Get())

{

 

if(printer["WorkOffline"].ToString().Equals("true")) 

                        {

 

                              printername=printer["Name"].ToString();

 

                              MessageBox.Show(printername+"-Offline");

 

                        }

}

Hope u have enjoyed this article.

Up Next
    Ebook Download
    View all
    Learn
    View all