Solved

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

Posted on 2008-06-23
10
399 Views
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.
         System.Drawing.Printing.PrinterSettings.InstalledPrinters;
But I want all the printers available on a intranet network. which may or  may not be installed on a server machine.
0
Comment
Question by:techprocess
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21853198
0
 
LVL 3

Author Comment

by:techprocess
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"])

                {

                    ddlPrinter.Items.Add(Convert.ToString(mo[pd.Name]));

                }

            }

        }

}

Open in new window

0
 
LVL 7

Expert Comment

by:maXXXeE
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
or
2) Let the app send or periodically update the printer details to the server via web service.
0
 
LVL 7

Expert Comment

by:maXXXeE
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.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 21855442
0
 
LVL 14

Assisted Solution

by:Dustin Hopkins
Dustin Hopkins earned 250 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

0
 
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.
0
 
LVL 5

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
A short film showing how OnPage and Connectwise integration works.

932 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now