How to get the names of all printers in a network (intranet) in a asp.net web app.

Posted on 2008-06-23
Medium Priority
Last Modified: 2013-12-16
How to get the names of all printers in a network (intranet) in a asp.net, c#.net  web app.

I have used the following code. but It only returns the name of printers installed on the server machine.
But I want all the printers available on a intranet network. which may or  may not be installed on a server machine.
Question by:techprocess
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2

Author Comment

ID: 21853277
I have tried this code. But it only gives the names of the printers installed on server computer. And not on the intranet.
using System.Management;
public void fn(){
// Use the ObjectQuery to get the list of configured printers
        System.Management.ObjectQuery oquery =
            new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
        System.Management.ManagementObjectSearcher mosearcher =
            new System.Management.ManagementObjectSearcher(oquery);
        System.Management.ManagementObjectCollection moc = mosearcher.Get();
        foreach (ManagementObject mo in moc)
            System.Management.PropertyDataCollection pdc = mo.Properties;
            foreach (System.Management.PropertyData pd in pdc)
                if ((bool)mo["Network"])

Open in new window


Expert Comment

ID: 21853408
I am not aware of any direct way to query all the printers in the network, specially if these are connected to computer via USB instead of directly connected to network via lan.

But you can do a workaround.

You can write a small app and run it as a service in client machines.
Then you can get the info in either of the 2 ways
1) Query each of these apps from your server when required
2) Let the app send or periodically update the printer details to the server via web service.
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -


Expert Comment

ID: 21853550
Another way, is to install remote printer drivers of all the printers in the intranet.
This might not be possible always based on the network environment.

In this case you can use the above code to get the printer and also do any printing tasks from the server.
LVL 70

Accepted Solution

Éric Moreau earned 1000 total points
ID: 21855442
LVL 14

Assisted Solution

by:Dustin Hopkins
Dustin Hopkins earned 1000 total points
ID: 21855871
I use this in a console application, but it wouldn't take much to port it into a web app
This returns "servername-printername"

    DirectoryServices.DirectoryEntry deParent = new DirectoryServices.DirectoryEntry(); 
    deParent.Username = SvcAcct; // Domain account username
    deParent.Password = SvcPass; // Domain account password
    deParent.AuthenticationType = DirectoryServices.AuthenticationTypes.Secure; 
    DirectoryServices.DirectorySearcher ds = new DirectoryServices.DirectorySearcher(deParent); 
    ds.Filter = "(&(ObjectCategory=printQueue))"; 
    foreach (DirectoryServices.SearchResult result in ds.FindAll()) { 
        Console.WriteLine(result.GetDirectoryEntry().Name); //<-- this is where you would change to response.write/import row into dataset ect.

Open in new window

LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21855936
Oh yeah, forgot to mention, that will only return all printers that are published in active directory/shared.

Expert Comment

ID: 21862956
i am glad it helps. I've ever had a task to list all printer but cancelled. This is what i remember.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question