How to obtain the camera device list on your PC and enable/disable camera status using Windows APIs?

Zhu Jeremy 1 Reputation point
2021-03-01T06:54:33.07+00:00

Hi,

We have a requirement to get the camera devices and the status of them on a PC. The launguage uses C#.
We tried to use SetupDiEnumDeviceInterfaces to enum all the device interface on the PC, but there is not a flag to show which device is a camera.
We also tried to use WMI API to get camera device, but it seems no camera devices listed.

Could any one give me some suggestions?
And about the status (enabled/disabled) of the device, how to obtain it?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,543 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2021-03-01T09:06:04.59+00:00

    With SetupDI APIs, you can get them with Class Guids like Camera Device, Imaging Device, USB
    (System-Defined Device Setup Classes Available to Vendors)
    I have only a Virtual Camera and I get it with Imaging Device {6bdd1fc6-810f-11d0-bec7-08002be2092f}

    You can also use DirectShow
    I had posted a sample adapted from MS SDK in this thread in VB (easy to convert into C#, function FindCaptureDevice)

    1 person found this answer helpful.