471,338 Members | 1,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 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 4915
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bill Gates | last post: by
7 posts views Thread by trint | last post: by
reply views Thread by prakashkoshti | last post: by
reply views Thread by rosydwin | last post: by

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.