列出可用的网络打印机(也未安装) [英] List available network printers (non-installed as well)
问题描述
这意味着我能够枚举所有打印机(网络打印机和本地打印机),但前提是它们都安装在我的PC上
Meaning i am able to enum all printers (network and local) but ONLY if they are installed on my PC
但是,我希望能够列出未安装的那些,并且可以使用(内置Windows的)添加打印机"对话框看到.
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.
是否有可能,因为我在浏览各种论坛/论坛(包括stackexchange)时找不到任何有用的信息.
Is it even possible as i couldn't find anything useful browsing various forums/boards including stackexchange.
意思是我也尝试了内置的.NET类和WMI(SELECT * from Win32_Printer
),但显然它们仅列出了已安装的打印机.
Meaning i tried the built-in .NET classes and WMI as well (SELECT * from Win32_Printer
) but obviously they list only the installed printers.
非常感谢您
请注意,建议的答案并不针对未安装的打印机,而仅针对已安装的打印机.我已经能够列出这些.谢谢
please notice that suggested answer does not address non-installed printers but rather only installed ones. I am already able to list those. Thx
推荐答案
我不相信.NET中有任何功能可以做到这一点,您将需要进行本机调用. 这是MSDN页面关于如何枚举网络资源,您需要做的是P/调用WNetEnumResource
函数以获取
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.
您正在寻找dwType
为RESOURCETYPE_PRINT
的对象,找到它们时,请选中lpRemoteName
以获取打印机的名称.
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.
此处是 a的链接示例代码段来实现其用法(即使URL指出它是VB,代码也使用C#).我将其张贴在这里,但是页面上的注释明确地不允许未经作者许可而复制和粘贴脚本.
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.
这篇关于列出可用的网络打印机(也未安装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!