List available network printers (non-installed as well)

1.1k views Asked by At

Meaning i am able to enum all printers (network and local) but ONLY if they are installed on my PC

However i want to be able to list those that are not installed and can be seen by using (windows built-in) ADD PRINTER dialog.

Is it even possible as i couldn't find anything useful browsing various forums/boards including stackexchange.

Meaning i tried the built-in .NET classes and WMI as well (SELECT * from Win32_Printer) but obviously they list only the installed printers.

Thank you so much in advance

EDIT: please notice that suggested answer does not address non-installed printers but rather only installed ones. I am already able to list those. Thx

1

There are 1 answers

4
Scott Chamberlain On BEST ANSWER

I do not believe there is anything in .NET that can do this, you will need to make a native call. Here is the MSDN page about how to enumerate network resources, what you will need to do is P/Invoke the WNetEnumResource function to get NETRESOURCE objects back.

You are looking for objects that have a dwType of RESOURCETYPE_PRINT, when you find them you check lpRemoteName to get the name of the printer.

Here is a link to a example snippet implementing its use (Even though the URL states it is VB the code is in C#). I would post it here but the note on the page expressly does not allow copying and pasting of the script without permission of the author.