473,383 Members | 1,885 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,383 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 5209
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.