Click here to Skip to main content
15,122,218 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
Can anyone tell me how to get a list of all printers on a network?
I have tried using WMI but the following code only gives me a list of local printers

here is the code that i tried.
//--set the scope of this search to the local machine
              ManagementScope scope = new ManagementScope(@"\root\cimv2");

              //--connect to the machine
              scope.Connect();

              //--query for the ManagementObjectSearcher to get all printer
              SelectQuery selectQuery1 = new SelectQuery();
              selectQuery1.QueryString = "Select * from win32_Printer";
              ManagementObjectSearcher obj = new ManagementObjectSearcher(scope,  selectQuery1);
              ManagementObjectCollection printers = obj.Get();

               //--now loop through each printer instance returned
                  foreach (ManagementObject printer in printers)
                  {
                      //--first make sure that there is a printer
                      if (printer != null)
                      {
                          str = printer["Name"].ToString().ToLower();

                          //--check if it matches the name provided
                          if (str.ToUpper().Equals("MyPrinterName".ToUpper()))
                          {
                              //--since we found a match check it's status
                              if  (printer["WorkOffline"].ToString().ToLower().Equals("true") || printer["PrinterStatus"].Equals(7))
                              {
                                  //--it's offline
                                  online = false;
                              }
                              else
                              {
                                  //--it's online
                                  online = true;
                              }
                          }
                      }
                      else
                      {
                          throw new Exception("No printers were found");
                      }
                  }


lease Help me.
Posted
Updated 21-Apr-11 2:41am
v2
Comments
Toniyo Jackson 21-Apr-11 7:42am
   
Added pre tag

1 solution

There's no one method that's going to get all printers. It depends on how your printers are connected to the network. Are they all available through a single print server? Are they in ActiveDirectory? Are they just sitting around with IP addresses so any client install their own drivers and print direct IP to them??
   
Comments
anvas kuttan 21-Apr-11 8:00am
   
Thanks for the post... once i run the same code in a windows application it will return all the printer including network printer in my system ...but that i8s not working in asp.net my system is hosted in iis
Prasanta_Prince 25-Apr-11 3:15am
   
There are lots of Things doesnot work properly in web application after hosting or Publish.
Member 10540081 27-Jan-14 23:26pm
   
but iam using java technology how can i know network level printers ins status directly
Dave Kreskowiak 27-Jan-14 23:33pm
   
First, you're replying to a post that's 3 YEARS old. Don't. Create your own thread with the full details of your question.

Second, I have no idea what you're talking about.

zainab Abo_Saibae 12-Apr-17 2:52am
   
Can I This Example With VB.Net
Dave Kreskowiak 12-Apr-17 8:59am
   
No. You didn't really read the post, did you?

Also, we're not in the business of writing your code for you. There's just way too much code to write for this for every situation for every printer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900