How to enumerate all the printers on the network

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Rizzo

    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);
    DirectorySearch er mySearcher = new DirectorySearch er(entry);
    mySearcher.Filt er = "(objectCategor y=printer)"
    foreach(SearchR esult result in mySearcher.Find All())
    {
    strName = result.GetDirec toryEntry().Nam e;
    }

    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.
  • Peter Duniho

    #2
    Re: How to enumerate all the printers on the network

    On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <none@none.netw rote:
    [...]
    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

    Comment

    • =?UTF-8?B?QXJuZSBWYWpow7hq?=

      #3
      Re: How to enumerate all the printers on the network

      Peter Duniho wrote:
      On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <none@none.netw rote:
      >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.Manageme nt;

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

      Arne

      Comment

      • Frank Rizzo

        #4
        Re: How to enumerate all the printers on the network

        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 <none@none.netw rote:
        >>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.Manageme nt;
        >
        namespace E
        {
        public class Program
        {
        public static void Main(string[] args)
        {
        WqlObjectQuery q = new WqlObjectQuery( "SELECT * FROM
        Win32_Printer") ;
        ManagementObjec tSearcher res = new ManagementObjec tSearcher(q);
        foreach (ManagementObje ct p in res.Get())
        {
        Console.WriteLi ne(p["PortName"] + " : " +
        p["DriverName "] + " : " +p["Status"]);
        }
        }
        }
        }
        >
        Arne

        Comment

        • =?UTF-8?B?QXJuZSBWYWpow7hq?=

          #5
          Re: How to enumerate all the printers on the network

          Frank Rizzo wrote:
          Arne Vajhøj wrote:
          >Peter Duniho wrote:
          >>On Fri, 25 Jul 2008 14:36:11 -0700, Frank Rizzo <none@none.netw rote:
          >>>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.Manageme nt;
          >>
          >namespace E
          >{
          > public class Program
          > {
          > public static void Main(string[] args)
          > {
          > WqlObjectQuery q = new WqlObjectQuery( "SELECT * FROM
          >Win32_Printer" );
          > ManagementObjec tSearcher res = new
          >ManagementObje ctSearcher(q);
          > foreach (ManagementObje ct p in res.Get())
          > {
          > Console.WriteLi ne(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

          Comment

          Working...