WIA.DeviceManager.DeviceInfos.Count = 0. Why?

Evgeny picture Evgeny · Feb 10, 2009 · Viewed 9.5k times · Source

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:

  • Download wiaaut.dll
  • Copy it to system32
  • Register it with "regsvr32 wiaaut.dll" (successfully)
  • Add reference to my project in Visual Studio.NET
  • Check that the Windows Image Acquisition (WIA) service is running

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

Answer

vander pina picture vander pina · May 16, 2012
 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..