I have searched for several days to no avail. I am trying to simply list to a text file the Image Device Names i.e. webcams using c#. I know I can use System.IO.Ports to get comports, which I am doing, but I cannot find a simple way to list the Image Devices.
I have been able to find the WIA devices with this code but not non-WIA Devices:
    private static void DoWork()
    {
        var deviceManager1 = new DeviceManager();
        for (int i = 1; (i <= deviceManager1.DeviceInfos.Count); i++)
        {
           // if (deviceManager1.DeviceInfos[i].Type !=   
     WiaDeviceType.VideoDeviceType) { continue; }
     Console.WriteLine(deviceManager1.DeviceInfos[i].
     Properties["Name"].get_Value().  ToString());
     }
As I answered in this question, you can do it without external libraries by using WMI.
Add using System.Management; and then:
public static List<string> GetAllConnectedCameras()
{
    var cameraNames = new List<string>();
    using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
    {
        foreach (var device in searcher.Get())
        {
            cameraNames.Add(device["Caption"].ToString());
        }
    }
    return cameraNames;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With