2

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

Elizabeth Dimova
  • 255
  • 1
  • 3
  • 19

1 Answers1

0

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.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • thank you so much about this... it looks very promising and i am about to test the suggested code. Will keep you updated. Thank you again – Elizabeth Dimova Jun 10 '15 at 14:00
  • Hmm i guess i cannot compile that code. I get some errors (Method must have a return type) on the line: //now call the function passing a null WNETOE(null); – Elizabeth Dimova Jun 10 '15 at 14:37
  • i was able to compile the project. Worked fine though i am not quite sure how to list only the printers. I'll keep analyzing the code. Thx – Elizabeth Dimova Jun 10 '15 at 14:47
  • Thank you for updating the answer. It's much appreciated. Meaning i a able to check the type but they all return RESOURCETYPE_ANY ... though i can see the non-installed printer via "Add Printer" dialog. Any ideas? – Elizabeth Dimova Jun 10 '15 at 15:45