How can I get a list all of camera devices attached to my PC using USB (WebCams) but also the build in camera that the laptops have.
            Asked
            
        
        
            Active
            
        
            Viewed 1.1k times
        
    3 Answers
13
            
            
        A simple solution without any external library is to use 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;
}
        Francesco Bonizzi
        
- 5,142
 - 6
 - 49
 - 88
 
- 
                    1This is a better solution than the accepted answer (may not have been available at the time of the accepted answer), as it is more general. Thank you! – CoolBots Dec 30 '21 at 22:25
 - 
                    1This will get scanners as well, but this is the best answer so far – Flying light Jan 24 '22 at 06:03
 - 
                    For full list of properties: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity – Trevy Burgess Jul 19 '22 at 20:06
 
7
            I've done this before - use http://directshownet.sourceforge.net/ to give you a decent .net interface to DirectShow, then you can just use the following code:
  DsDevice[] captureDevices;
  // Get the set of directshow devices that are video inputs.
  captureDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);    
  for (int idx = 0; idx < captureDevices.Length; idx++)
  {
    // Do something with the device here...
  }
        Alistair Evans
        
- 36,057
 - 7
 - 42
 - 54
 
0
            
            
        Hope it helps other users
//using System.Management;
    public void GetCameras()
    {
        List<string> cameras = new List<string>();
        var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')");
        
        foreach (var device in searcher.Get())
        {
            cameras.Add($"Device: {device["PNPClass"]} / {device["Caption"]} / {device["Description"]} / {device["Manufacturer"]}");
        }
        
        File.WriteAllLines(@"C:\out\cameras.txt", cameras);
    }
- 
                    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 29 '22 at 00:19
 - 
                    Welcome to Stackoverflow. This question is asked more than 9 years ago and it has an accepted answer. Please add some details about the reason you are adding a new answer. – MD Zand Nov 30 '22 at 12:57