是否有可能将虚拟打印机与物理打印机不同? [英] Is there a possibility to differ virtual printer from physical one?
问题描述
我有一份在 WinXP 中可用的所有打印机的列表.我需要代码(最好是 .NET)来从这个列表中过滤掉所有的虚拟打印机.有可能吗?我分析了 Win32_Printer wmi 类的所有属性,但没有找到合适的.
I have a list of all printers available in WinXP. I need the code (ideally .NET) to filter out all the virtual printers from this list. Is it possible to do? I analyzed all the properties of Win32_Printer wmi class but can't see any suitable one.
推荐答案
我知道这是一个老问题,但这个答案可能对遇到同样问题的人有所帮助.
I know this is an old question but this answer may be helpful to someone with the same problem.
如果我对虚拟打印机"的理解是正确的.您可以检查 WMI 属性PrintProcessor"并忽略winprint".据我所知,这将忽略所有基于 Windows 7 软件的打印机选项.下面是一些示例代码来演示这一点.返回打印机名称.
If my understanding of a "virtual printer" is correct. You could check the WMI property "PrintProcessor" and ignore "winprint". To my knowledge this will ignore all of Windows 7 software based printer options. Here is some sample code to demonstrate that. Returns the printer name.
using System.Management;
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_Printer");
foreach (ManagementObject obj in searcher.Get())
{
if(obj != null)
{
if(obj["PrintProcessor"].ToString().ToUpper() != "WINPRINT")
{
Console.WriteLine(obj["Name"]);
}
}
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
这篇关于是否有可能将虚拟打印机与物理打印机不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!