问题
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