How can I locate all the network printers in the enterprise?

浪子不回头ぞ 提交于 2019-12-14 03:48:11

问题


When I go to Printers and Faxes dialog, I can click the Add a printer link, select Network Printer, then Find a printer in the directory. From there I get a dialog box which lets me find ALL printers in the enterprise.

I need to find all the network printers with my code. How can I do this?

Note that I am not talking about network printers that are connected to my PC, but all network printers in the enterprise (my workplace has almost 4000 printers).

P.S. PrintServer().GetPrintQueues only returns printers attached to the computer.

P.P.S. Here is a short video of what I want: http://www.angryhacker.com/toys/FindAllPrinters/FindAllPrinters.html


回答1:


DirectorySearcher with a filter for (objectClass=printer) (objectClass=printQueue)should do the trick.

using (var e = new DirectoryEntry("LDAP://DC=example,DC=com"))
    using (var s = new DirectorySearcher(e)) {
        s.Filter = "(objectClass=printQueue)";

        using (var c = s.FindAll()) {
            WL("Returned {0} objects", c.Count);
            foreach (SearchResult r in c) {
                WL("{0}", r.Path);
            }
        }
    }


来源:https://stackoverflow.com/questions/2556528/how-can-i-locate-all-the-network-printers-in-the-enterprise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!