Pregunta

I have been trying to find all printers in the network.But, I always ended up with printers which are already connected with my computer. When I try to add printers at Control Panel\Hardware and Sound\Devices and Printers, I could find many more printers available in the network.

Please note that I don't have printer server. All printers are IP based.

I used following code:

WqlObjectQuery wQuery = new WqlObjectQuery("SELECT * FROM Win32_Printer Where " +
    "Local = FALSE");
ManagementObjectSearcher res = new ManagementObjectSearcher(wQuery);
if ((res.Get().Count > 0))
{
    foreach (ManagementObject printer in res.Get())
    {
        Console.WriteLine(printer["PortName"] + " : " + printer["DriverName"] +
            " : " + printer["Status"]);
    }
}
else { Console.WriteLine("No printers found"); }

In the query, if I set local to true i get printers installed on my computer.

I also tried with similar questions here, but still no luck.

Any help appreciated.

¿Fue útil?

Solución

The WMI cannot enumerate network printers, only can list the shared printers registered in the local machine. To this task you can use the WNetEnumResource, WNetOpenEnum and WNetCloseEnum WinApi functions. Some time ago I wrote a sample of this using .Net Try this article Enumerating All Network resources using Delphi Prism, the code uses the Oxygene language but can be translated to C# easily.

Otros consejos

As far as I know, what you're looking for is outside of WMI's capabilities.

I know you dont have a print server, but if all the printers are at least connected to other machines, then a quick workaround might be to use PSExec to run your printer finding script locally on all computers on your network (or maybe a login script). You could simply make your printer finding script write to a network share, and then review the information once the execution completes.

Otherwise I would suggest using a network mapping tool like ZenMap or a network monitoring tool like Spiceworks ( www.spiceworks.com) to fingerprint your devices.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top