How to enable/disable webcam by script (Win 10)

Viewed 8326

I'm using for win 10 on my laptop and sometimes I need ti enable/disable my build in webcam and mic by any script or .exe file. In other words I need to switch this one by script: WebCam Settings I tried to find something in Google, but without success. Tell me where to start?

2 Answers

You can disable and enable your webcam using PowerShell script.

  1. List all your cameras:

    Get-PnpDevice -FriendlyName *webcam* 
    
  2. Filter camera by status:

    Get-PnpDevice -FriendlyName *webcam*  -Status OK
    
  3. Disable the camera:

    Disable-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam*  -Status OK).InstanceId    
    
  4. Enable the camera:

    Enable-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam*  -Status Error).InstanceId
    

enter image description here

Mmmmh... it works if you are not using the webcam, but if it is still active it shows this error (running the powershell script as administrator):

Disable-PnpDevice : Generic failure

At line:1 char:1

  • Disable-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName "USB Video ...
  •   + CategoryInfo          : NotSpecified: 
    

(Win32_PnPEntity...7&169FD4E3&...):ROOT\cimv2\Win32_PnPEntity) [Disable-PnpDevice], > CimException

  • FullyQualifiedErrorId : HRESULT 0x80041001,Disable-PnpDevice
  • Is there any way to turn it off while it's still in use ? My problem is that after I end a Microsoft Teams meeting, I see that the cam is still in use, because I see its led still ON...
Related