1

I use my laptop as a desktop quite often, about 75% of the time. As a desktop setup, it has a monitor, speakers, keyboard, mouse and webcam connected externally—the latter three over USB.
It is then positioned such that its integrated webcam becomes useless for face recognition and video chats, yet some of the programs I use don't offer any way to choose a default webcam.

So I was wondering if there is any way, through a utility, scripting or otherwise, to automatically disable the built-in webcam when an external one is connected.

(I'm using Windows 7 on an Asus Zenbook Prime UX32VD if that helps.)

  • I think I've got a working script which should handle that. Can you confirm that disabling the built-in webcam will force all programs to detect the external one? – and31415 Jan 19 '14 at 19:23
  • @and31415, I will give that a try and get back to you ASAP. – oKtosiTe Jan 20 '14 at 12:41
  • Yes, disabling the device in the Device Manager has the desired effect. @and31415 – oKtosiTe Jan 20 '14 at 12:45
  • Did you check the event viewer for any events? – tumchaaditya Jan 21 '14 at 18:19
  • 1
    You can create a scheduled task on that event ID and make it run a batch file that enables/disables required devices – tumchaaditya Jan 22 '14 at 23:07
5
+50

Theory first

  • We need to periodically check whether the external webcam is connected to the computer.
  • When the external webcam is plugged in, the built-in one should be disabled.
  • Then built-in device should be enabled back after the external camera is unplugged.

Preliminary steps

The proposed solution uses batch scripting and task scheduling techniques to handle all of this. Before we can actually jump to the juicy bits, we need to do a few things.

Obtain the Device Console (DevCon) utility

DevCon is a command-line tool that displays detailed information about devices, and lets you search for and manipulate devices from the command line. DevCon enables, disables, installs, configures, and removes devices on the local computer and displays detailed information about devices on local and remote computers.

  1. Download the appropriate .cab package depending on the operating system:

  2. Open the .cab archive and extract the file named fil[some letters and numbers]. It should be about 80 KB.

  3. Rename it to devcon.exe.

Note In order to enable/disable any device, devcon.exe must be run with admin rights.

Determine the required hardware identifiers

Windows identifies devices and the setup classes they belong to by using a special set of identifiers. These identifiers are used to match hardware devices with the device drivers that allow them to communicate with Windows.

One or more device IDs are assigned to a device by its manufacturer. One of them, the hardware ID, is very specific - down to the make, model, and even the firmware version of the device. Other device IDs are also assigned, and are more generic, with the IDs possibly being assigned to other devices from the manufacturer that are compatible at some level.

Source: Discovering Hardware IDs and Device Setup Classes for your Devices

  1. Plug the external webcam in.
  2. Open the Device Manager (devmgmt.msc).
  3. Find your built-in camera in the list.
  4. Right-click the entry for the device, and then click Properties.
  5. Select the Details tab and choose Hardware Ids from the property list.
  6. Right-click the first value shown and copy it. Take note of the value somewhere.
  7. Repeat steps 3-6 for the external webcam.

Creating the batch script

  1. Save the following code as WebcamCheck.cmd:

    @echo off
    
    REM ensure there at least 2 parameters
    if "%~2" == "" exit /b 2
    
    REM verify devcon.exe is not missing
    cd /d "%~dp0"
    if not exist devcon.exe exit /b 3
    
    REM set the interval to 15 seconds if not specified
    if "%~3" == "" (set interval=15) else (set interval=%3)
    
    :poll
    for /f "tokens=1 delims=\" %%G in ("%~2") do (devcon.exe find *%%G* | findstr /i /c:"%~2" >nul)
    goto :check%errorlevel%
    
    :check0
    devcon.exe status "%~1" | findstr /i /c:"disabled" >nul
    if %errorlevel% == 1 (devcon.exe disable "%~1")
    
    :wait
    timeout /t %interval% /nobreak >nul
    goto :poll
    
    :check1
    devcon.exe status "%~1" | findstr /i /c:"disabled" >nul
    if %errorlevel% == 0 (devcon.exe enable "%~1")
    goto :wait
    
  2. Copy the devcon.exe file and paste into the same directory as the file you just saved.

How it works

The script takes three parameters: the first one is the target device ID (the built-in webcam); the second one is the trigger device ID (the external webcam); the third one is the polling interval (in seconds), and it's optional.

At first the script will make sure there are enough parameters, and that devcon.exe isn't missing.

When no polling interval is specified, the default value will be used instead (15 seconds). The value is used to determine how many seconds should elapse between each device check. Lowering the value means the detection is faster, which in turns means there's more system overhead. Before trying a different value, test it with the default one and see how it goes. Either way, I wouldn't recommend going below 10 seconds.

The batch script requires generic device IDs, which use the following format:

XXX\VID_YYYY&PID_ZZZZ

XXX is the device class (e.g. USB, PCI, etc.); YYYY is the Vendor ID, an unique value assigned to hardware manufacturers; ZZZZ is the Product ID, which identifies the device model.

For example, if you got a device ID like this:

USB\VID_1D4D&PID_1002&REV_0039&MI_00

the generic ID would be:

USB\VID_1D4D&PID_1002

After checking whether the trigger device (external webcam) is connected, the script will either disable or enable the target device (built-in webcam), unless it's disabled/enabled already.

Scheduling it

The only thing we need now is to make the batch script start automatically at log on.

  1. Open the Task Scheduler (taskschd.msc) and click Action > Create Task.
  2. Name it WebcamCheck.
  3. While in the General tab, click Change User or Group.
  4. Type system in the textbox, click Check Names, and then click OK.
  5. Enable the Run with highest privileges option.
  6. Change the Configure for value to Windows 7, Windows Server 2008 R2.
  7. Select the Triggers tab, and click New.
  8. Change the Begin the task to At log on, then press OK.
  9. Switch to the Actions tab, and click New.
  10. Type "X:\Path\to\WebcamCheck.cmd" in the Program/script textbox, replacing it with the actual file path.
  11. Type "XXX\VID_YYYY&PID_ZZZZ" "AAA\VID_BBBB&PID_CCCC" in the Add arguments textbox, replacing the device IDs with the proper values.
  12. Click the Conditions tab and uncheck Start the task only if the computer is on AC power option.
  13. Select the Settings tab, and uncheck both the Allow task to be run on demand and Stop the task if it runs longer than fields.
  14. Enable the Run task as soon as possible after a scheduled start is missed option.
  15. Leave all other settings to default values and press OK.

Note If you want the built-in webcam to be disabled as soon as possible, connect the external one before logging in.


Update

Here's a simplified version of the batch script which will check the external camera only when started and then exit:

@echo off

REM ensure there at least 2 parameters
if "%~2" == "" exit /b 2

REM verify devcon.exe is not missing
cd /d "%~dp0"
if not exist devcon.exe exit /b 3

:check
for /f "tokens=1 delims=\" %%G in ("%~2") do (devcon.exe find *%%G* | findstr /i /c:"%~2" >nul)
goto :check%errorlevel%

:check0
devcon.exe status "%~1" | findstr /i /c:"disabled" >nul
if %errorlevel% == 1 (devcon.exe disable "%~1")
exit /b

:check1
devcon.exe status "%~1" | findstr /i /c:"disabled" >nul
if %errorlevel% == 0 (devcon.exe enable "%~1")
exit /b
|improve this answer|||||
  • I hope I still have enough time to test this before the bounty expires. If not I may award a new one later. While I don't need to have the computer continuously monitoring for an external camera, I believe I will be able to cherry pick a number of useful bits from your answer. – oKtosiTe Jan 23 '14 at 23:20
  • You mean checking for the external camera only while logging in would suffice for you? – and31415 Jan 23 '14 at 23:33
  • Yes, absolutely. – oKtosiTe Jan 24 '14 at 19:52
  • Anyway, I won't have time to check the answer yet, but since it looks like you were thinking in the same direction (devcon and a script) and put in quite some effort, the bounty is well-deserved IMO. Will almost certainly accept later. Thank you. – oKtosiTe Jan 24 '14 at 19:54
0

You can try to disable the webcam through the control panel or in device manager. This should allow for the external webcam to be installed and be the only webcam that is currently running. afterwards you can always just enable the device again.

Hope this helps.

|improve this answer|||||
  • 1
    My hope was to do this automatically somehow. It's still baffling to me that Windows doesn't have a setting for this... – oKtosiTe Jan 13 '14 at 18:31
  • @oKtosiTe: windows cant have everything you can imagine built in! – tumchaaditya Jan 18 '14 at 1:25
  • 1
    @tumchaaditya, and yet it can automatically cut the audio from the external speakers when headphones are plugged in, and turn off the laptop screen when an external monitor is plugged in. – Synetech Jan 18 '14 at 21:21
  • External speaker thing is typically handled by audio drivers and not windows itself. Search SU and you'll find tons of question saying that this feature is broken because of driver issue. And windows may or may not cut off laptop display depending on how you configured it to do the last time you connected external display. It just remembers that setting. – tumchaaditya Jan 18 '14 at 21:25
  • 1
    @tumchaaditya: Whether Windows has this feature built-in is irrelevant. I'll accept any answer that manages to automate this somehow, whether it be through a batch script, a utility, a wrapper driver or a shark with a frickin' laser attached to its head. – oKtosiTe Jan 20 '14 at 12:38
0

You can try a Portable freeware Aplication "WebCam On-Off v1.0" it has Cmd suppor too http://www.sordum.org/8585/webcam-on-off-dont-let-your-webcam-spy-on-you/

|improve this answer|||||
  • Welcome to Super User! Please read How do I recommend software for some tips as to how you should go about recommending software. At the very least you should provide some additional information about the software. – Mokubai Nov 22 '14 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.