Search code examples
c#windowscamera

Disabling the webcam programmatically under Windows


How can I disable the attached or built-in webcam(s) programmatically under Windows?

By disabling them, I mean that any program trying to access the cameras should either:

  • be unable to access them
  • be able to access them, but instead of the video feed, they should receive a black picture

Why I want to do this:

I have a laptop with a webcam. There's no easy way to disable it via software. I want to create an application with a button that disables the webcam, so that any application that wants to use it will be unable to, and a button to re-enable it. I don't want to put anything over the cam physically, otherwise I wouldn't be asking this question here.


Solution

  • Here are two links here on SO to enable/disable a device programmatically:

    How do I disable a system device?

    Win32 API function to programmatically enable/disable device

    There is also an official tool, DevCon, that you could automate.

    DevCon (Devcon.exe), the Device Console, is a command-line tool that displays detailed information about devices on computers running Windows. You can use DevCon to enable, disable, install, configure, and remove devices.