I'm trying to identify the scanners attached to the computer. One of the possible solutions is to use WIA (Windows Image Acquisition Automation Library).
These were my actions so far:
Next, I add and debug the following code:
WIA.DeviceManager manager = new WIA.DeviceManagerClass();
string deviceName = "";
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
{
if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
{
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name")
{
deviceName = ((WIA.IProperty)p).get_Value().ToString();
Console.WriteLine(deviceName);
}
}
}
}
However, the manager.DeviceInfos is always empty. I have 2 scanners attached, one of them shows in Control Panel->Scanners and Cameras, one doesn't, and both show under "Imaging Devices" in Device manager.
Any suggestion on why none are appearing in WIA.DeviceManager.DeviceInfos?
Running on Windows XP Service Pack 2
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name") <-- p is a property why cast like you doing above.
{
deviceName = ((WIA.IProperty)p).get_Value().ToString();
Console.WriteLine(deviceName);
}
}
try this:
deviceName = p.get_Value();
this will show like a error on visual studio but when you press f5 will compile. and will run..