List available network printers (non-installed as

2019-07-23 12:27发布

This question already has an answer here:

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

标签: c# list printers
1条回答
何必那么认真
2楼-- · 2019-07-23 12:44

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.

查看更多
登录 后发表回答