识别连接到计算机的扫描仪?
我正在开发的应用程序正在使用扫描仪,它可能属于几种类型之一。 我需要识别连接的扫描仪,提供从连接的扫描仪中选择默认扫描仪的选项,并在需要时更改此选择。 到目前为止,我想出了这个解决方案:
ManagementObjectSearcher search = new System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity");
ManagementObjectCollection deviceCollection = search.Get();
foreach (ManagementObject info in deviceCollection)
{
string deviceName = Convert.ToString(info["Caption"]);
if( /* check something about deviceName */)
{
// add a scanner to the list
}
}
这对我有用,因为我知道信息[“标题”]中会发生什么。 但是,有几个问题:
- 我知道我的设备将位于“成像设备”下。 有没有办法只识别“成像设备”分支的成员,而不循环遍历每个 PnP 设备? 刚刚发现我的电脑上的 deviceCollection 有 190 个条目。 如果能把它过滤到只有几个就太好了。 :)
- 对于我事先不知道要连接的扫描仪的型号/类型的情况,有没有办法识别该设备是扫描仪?
The application I'm working on is using a scanner, which may belong to one of a few types. I need to identify the attached scanner(s), give an option to select a default scanner from those attached and also change this selection whenever required. So far I came up with this solution:
ManagementObjectSearcher search = new System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity");
ManagementObjectCollection deviceCollection = search.Get();
foreach (ManagementObject info in deviceCollection)
{
string deviceName = Convert.ToString(info["Caption"]);
if( /* check something about deviceName */)
{
// add a scanner to the list
}
}
This works for me because I know what to expect in the info["Caption"].
However, there are a couple questions:
- I know my devices are going to be under "Imaging devices". Is there a way to identify only members of "Imaging devices" branch, without looping through every PnP device? Just found out that on my PC the deviceCollection has 190 entries. Would be really nice to filter it down to just a couple. :)
- Is there a way to identify that the device is a scanner, for the scenario where I have no idea beforehand about the model/type of a scanner that will be attached?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按照 此主题
You could try the Windows Image Acquisition Automation Library as suggested in this thread