识别连接到计算机的扫描仪?

发布于 2024-07-13 14:03:03 字数 763 浏览 9 评论 0原文

我正在开发的应用程序正在使用扫描仪,它可能属于几种类型之一。 我需要识别连接的扫描仪,提供从连接的扫描仪中选择默认扫描仪的选项,并在需要时更改此选择。 到目前为止,我想出了这个解决方案:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-07-20 14:03:03

您可以按照 此主题

You could try the Windows Image Acquisition Automation Library as suggested in this thread

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文