views:

249

answers:

1

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?
+1  A: 

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

Stuart Dunkeld
This approach 'works' in terms compiles and runs, but the manager.DeviceInfos.Count is 0. I'll keep searching for the reason why that's happening.
Evgeny
I guess I should accept the answer cause it SHOULD work ... I have no idea why it doesn't - possibly device drivers do not support WIA (???)
Evgeny