-1

I would like to Read the name of USB camera (i.e., HD USB camera) attached to Windows 10 and store the name as a variable in C#.

David
  • 11
  • 1

1 Answers1

2

You can try to filter the items in the Win32_PnPEntity class to only show items referring to the IMAGE or MEDIA category, which usually list items referring to the webcam connected to usb.

In the SQL command you can change the category.

    using System.Management;  

    private static void GetUSBDevices()
    {
        var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')");

        foreach (var device in searcher.Get())
        {
            Console.WriteLine($"Device: {device["PNPClass"]} / {device["Caption"]}");
        }
    }

You will need to add the System.Management dependency to the project.

Alberto Santos
  • 357
  • 1
  • 9