List available network printers (non-installed as well) [duplicate]

。_饼干妹妹 提交于 2019-12-11 02:47:25

问题


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:


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.



来源:https://stackoverflow.com/questions/30757779/list-available-network-printers-non-installed-as-well

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