6

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.

rid
  • 61,078
  • 31
  • 152
  • 193
  • Which cameras? Webcams, photo cameras connected by USB, video recorders perhaps? Be more specific. –  Oct 08 '11 at 11:07
  • ... and what do you mean by disabling them? You know that even if you can disable a device, the user can just unplug & plug it back in, right? – tenfour Oct 08 '11 at 11:09

5 Answers5

6

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.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • These look interesting, but how do I find all the devices that are cameras? – rid Oct 13 '11 at 12:41
  • 1
    @radu - what language are you using? (please update the question with tags) – Simon Mourier Oct 13 '11 at 16:08
  • I have no preference of language at this point, but I added C#. – rid Oct 15 '11 at 00:58
  • @Radu here is a link to list all the availble video capture device, it is in C++ though http://stackoverflow.com/questions/4286223/how-to-get-a-list-of-video-capture-devices-web-cameras-on-windows-c – Vamsi Oct 15 '11 at 07:30
  • hi is their any way to do it without system restart devcon requires restart – bhupinder Dec 19 '13 at 14:32
1
  1. A simple yet effective solution is to have an application on background which locks the camera by active capture from it (such as capture in minimal resolution, to Null Renderer filter, or perhaps paused capture would be even better). As long as your app acquired access to the camera noone else could be capturing from it.

  2. Another solution, more complicated and somewhat dangerous as for interaction with other applications, is to redefine (hook, substitute) System Device Enumerator class and intercept its enumeration of video input device category. Having hold of this, you can hide the camera and do not pass its enumeration to the application. The keyword here is CoTreatAsClass and this requires that you are familiar with COM. This will still let legacy applications access the camera via Video for Windows API (which you might be OK with).

Roman R.
  • 68,205
  • 6
  • 94
  • 158
1

You can write an application using DirectShow that takes control of the web cam which will prevent other applications from accessing it. You will probably have to use C++ and you will probably need Visual Studio 2005 or greater.

Start by downloading the Windows SDK: http://go.microsoft.com/fwlink/?LinkID=129787 After installing the SDK, open Visual Studio and open the solution at:

[SDK Root]\Samples\Multimedia\DirectShow\baseclasses\baseclasses.sln

[SDK Root] will typically be: C:\Program Files\Microsoft SDKs\Windows\v7.1

Build the solution which will create strmbase.lib (release) or strmbasd.lib (debug). This library is needed to build a DirectShow application.

Next open the AmCap sample at:

[SDK Root]\Samples\multimedia\directshow\capture\amcap\amcap.sln

Build and run AmCap. You should now be able to control the web cam. You can use AmCap as a basis for what you want to do or you may even be able to just modify AmCap for your needs.

Hope this helps.

Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38
0

The only way you can block a user from accessing a camera connected to the system is to uninstall the driver for it. That would be an extremely unfriendly thing to do!!

If you want to block the use of a system device from within your application, then all you have to do is remove the offending device from the list of available devices shown to the user.

Question: Why do you want to do this?

Escovado
  • 27
  • 1
  • 6
  • I have a laptop with a webcam. There's no easy way to disable it. 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. – rid Oct 08 '11 at 23:03
  • 3
    Radu, cover the lens with a cap. That's probably the easiest way. – Joey Oct 08 '11 at 23:17
  • 1
    @Joey, thanks for the suggestion, but that's not what I'm looking for. – rid Oct 10 '11 at 12:24
  • You can disable the device in Device Manager. Note that won't stop somebody from plugging in a *different* webcam. – Raymond Chen Oct 10 '11 at 17:44
-1

Well you don't need programming for this... I'm sure your aware of what the task manager is. Just create a .bat file (aka the .exe file) that kills the webcam process... and have another .bat file to open it back up? I mean this would work for any webcam on windows, BUT if you wanted to do it programatically (is that word right? lol) then you'd have to supply us with the information on what type of webcam it is and such...

and just in case you don't know how to make a bat file: open up an empty .txt file type in:

command.com taskkill /IM notepad.exe

and save the file as anything.bat, and be sure to change the file type(right under where you name the file) click on where it says Save as type:*txt, and select all files instead.

Gabriel
  • 3,039
  • 6
  • 34
  • 44