473,394 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to enumerate all the printers on the network

I basically need a list of printers that's returned by the Find Printers
dialog ( http://www.sqleffects.com/mystuff/findPrinters.png ). I've
tried the path of

DirectoryEntry entry = new DirectoryEntry(strPath);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(objectCategory=printer)"
foreach(SearchResult result in mySearcher.FindAll())
{
strName = result.GetDirectoryEntry().Name;
}

but nothing was returned.

I am wondering what mechanism the Find Printers dialog is using? Is it
hitting up the active directory? How does it find all the printers?

Thanks.
Jul 25 '08 #1
4 5211
On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <no**@none.netwrote:
[...]
I am wondering what mechanism the Find Printers dialog is using? Is it
hitting up the active directory? How does it find all the printers?
Printers aren't really in a directory per se. They are simply installed
drivers. You can use (via p/invoke) the unmanaged EnumPrinters() function
to find all the installed printers. It's possible WMI in .NET has an
equivalent method, but I don't know it off the top of my head.

Pete
Jul 25 '08 #2
Peter Duniho wrote:
On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <no**@none.netwrote:
>I am wondering what mechanism the Find Printers dialog is using? Is
it hitting up the active directory? How does it find all the printers?

Printers aren't really in a directory per se. They are simply installed
drivers. You can use (via p/invoke) the unmanaged EnumPrinters()
function to find all the installed printers. It's possible WMI in .NET
has an equivalent method, but I don't know it off the top of my head.
It can.

using System;
using System.Management;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
WqlObjectQuery q = new WqlObjectQuery("SELECT * FROM
Win32_Printer");
ManagementObjectSearcher res = new ManagementObjectSearcher(q);
foreach (ManagementObject p in res.Get())
{
Console.WriteLine(p["PortName"] + " : " +
p["DriverName"] + " : " +p["Status"]);
}
}
}
}

Arne
Jul 26 '08 #3
Arne,

This code only brings back locally installed printers. I want the
printers that are returned by the Find Printers dialog, which somehow
seems to find every single printer in the enterprise (hundreds).

Arne Vajhøj wrote:
Peter Duniho wrote:
>On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <no**@none.netwrote:
>>I am wondering what mechanism the Find Printers dialog is using? Is
it hitting up the active directory? How does it find all the printers?

Printers aren't really in a directory per se. They are simply
installed drivers. You can use (via p/invoke) the unmanaged
EnumPrinters() function to find all the installed printers. It's
possible WMI in .NET has an equivalent method, but I don't know it off
the top of my head.

It can.

using System;
using System.Management;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
WqlObjectQuery q = new WqlObjectQuery("SELECT * FROM
Win32_Printer");
ManagementObjectSearcher res = new ManagementObjectSearcher(q);
foreach (ManagementObject p in res.Get())
{
Console.WriteLine(p["PortName"] + " : " +
p["DriverName"] + " : " +p["Status"]);
}
}
}
}

Arne
Jul 29 '08 #4
Frank Rizzo wrote:
Arne Vajhøj wrote:
>Peter Duniho wrote:
>>On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <no**@none.netwrote:
I am wondering what mechanism the Find Printers dialog is using? Is
it hitting up the active directory? How does it find all the printers?

Printers aren't really in a directory per se. They are simply
installed drivers. You can use (via p/invoke) the unmanaged
EnumPrinters() function to find all the installed printers. It's
possible WMI in .NET has an equivalent method, but I don't know it
off the top of my head.

It can.

using System;
using System.Management;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
WqlObjectQuery q = new WqlObjectQuery("SELECT * FROM
Win32_Printer");
ManagementObjectSearcher res = new
ManagementObjectSearcher(q);
foreach (ManagementObject p in res.Get())
{
Console.WriteLine(p["PortName"] + " : " +
p["DriverName"] + " : " +p["Status"]);
}
}
}
}
This code only brings back locally installed printers. I want the
printers that are returned by the Find Printers dialog, which somehow
seems to find every single printer in the enterprise (hundreds).
You can get WMI to return all printers available at servers via
ManagementScope.

But maybe LDAP is more what you want.

Arne
Aug 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bill Gates | last post by:
Hello, I am having a little trouble accessing a list of printers on our Network through a web service... I am using the PrinterSettings.InstalledPrinters to access a list of printers installed...
7
by: trint | last post by:
How can I add all the network printers to a combobox? Thanks, Trint
1
by: Phil Galey | last post by:
Is there any way of enumerating all printers, including network printers in VB.NET? printing.PrinterSettings.InstalledPrinters only enumerates printers attached to the local workstation. ...
0
by: prakashkoshti | last post by:
I have an applicaiton developed in ASP.Net. I have installed network printers on my machine. (Installed printers include both USB and COM) When I try to print from other interactive applications...
0
by: Lars | last post by:
I am using Microsoft .NET (2.0) PrintPreviewDialog and all works well when the Windows default printer is set to a local printer or a network printer on a Windows server, but if I set it to a...
1
by: gnusmsa | last post by:
ASP.NET 2.0 (C#) application Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged into server as a domain user that is in the...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
5
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged...
2
by: calan_svc | last post by:
I have a dll I wrote in VB6. Basically, it can list all the printers it finds as well as print to a selected printer. I created a test app in VB6, added the dll as a reference, and added the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.