Search code examples
c#winapicamera

How to detect Cameras attached to my machine using C#


I am able to know the sound devices and USB Devices attached to my PC but not getting any way to find Cameras attached to my machine. Used below code to get Sound Devices

Console.WriteLine("Win32 SoundDevices\r\n===============================");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from Win32_SoundDevice");
            foreach (ManagementObject soundDevice in searcher.Get())
            {
                //Console.WriteLine("Device found: {0}\n", soundDevice.ToString());
                Console.WriteLine("Device found: {0}\n", soundDevice.GetPropertyValue("ProductName"));
            }
            Console.WriteLine("Search complete.");

Solution

  • This tool will prove helpful:

    http://www.microsoft.com/en-us/download/details.aspx?id=8572

    I'm fairly certain there's no equivalent string you can send to ManagementObjectSearcher() for webcams specifically. There is the "Win32_USBControllerDevice" which you can then determine if it is a webcam or not.

    A better solution altogether is to take advantage of DirectShow.NET