2

My PC is connected to a LAN and I want to get all the printers in the network to which I connected. I tried PrinterSettings.InstalledPrinters in my code. It returns the printer that I had configured in my computer.Actually there are 2 more printers connected in the network. I tried this code also,

        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"])
                {

                    comboPrinters.Items.Add(pd.Name);
                }
            }
        }
        MessageBox.Show(p);

    }

It also give the same output.I searched in many sites but couldn't find any solution. Any suggestions??

Thanks in advance.

NB: Our AD is not well maintained.

Sudix
  • 640
  • 8
  • 27
  • 1
    possible duplicate of [How can I locate all the network printers in the enterprise?](http://stackoverflow.com/questions/2556528/how-can-i-locate-all-the-network-printers-in-the-enterprise) – Justin Pihony Jun 04 '13 at 04:44
  • 1
    not really clear if that's a duplicate ... the linked question is about finding the printes by LDAP lookup ... here we don't even know if there is such a directory ... or if *all* printers are listed in the directory ... a little more information about the network environment would be nice – DarkSquirrel42 Jun 04 '13 at 05:59
  • Check this SO question: http://stackoverflow.com/questions/1018001/is-there-a-net-way-to-enumerate-all-available-network-printers – unlimit Jun 04 '13 at 06:01
  • thanks for your replies... @unlimit The answer in that link is the code that I've mentioned in the question.. – Sudix Jun 04 '13 at 06:18
  • @DarkSquirrel42 - Please specify that what kind information do you expect.. Also does Socket programming help for this problem?? – Sudix Jun 04 '13 at 06:19
  • you are trying to enumerate printers ... ok ... the WMI stuff you got there will tell you about all printers known to the local system ... if you want more printers, you need to have information about those somewhere ... that can be a number of printers available in your AD ... you can try to find some by broadcast discovery protocols (Zeroconf / mDNS) or even portscans for the usual suspects (well known printing services ports) ...there are numerous ways ... the probelm is, that we don't know what your infrastructure is capable of ... or what your application should be capable of ... – DarkSquirrel42 Jun 04 '13 at 21:12
  • or in other words: how would you enumerate those printers manually? ... add a local network printer by searching for it in the directory? in that case you can use the code linked by Justin Pihony ... that would be the LDAP case ... – DarkSquirrel42 Jun 04 '13 at 21:14

0 Answers0