Monday, February 9, 2009

Finding a scanner

I need to find out what scanners are attached to the computer. I also need to give the user of my application an option to select the default scanner, and to change this selection at any time. Fortunately, the scanner can only be one of a few models. Therefore, this is the solution I came up with so far:

ArrayList scanners = new ArrayList();

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 deviceName for certain substrings */)

However, there are at least two things that can be improved, though I don't know if they're possible.

First, I would like to get only those devices that are under "Imaging devices" in Device Manager. That would be a huge improvement as I currently have almost 200 entries in the deviceCollection, and only 2 of them are under "Imaging Devices".

Also, I would like to find a way to check if the device is a scanner. That would help to provide a "general" solution where the scanner attached may be of any model.

by . Also posted on my website

No comments: