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?