devcon.exe cannot disable usb device

0

I have a USB barcode scanner connected to a windows 10 tablet. I need to switch this barcode scanner on/off from a powershell script running on windows).

Reading the microsoft doc online, would seem tat devcon.exe is the way to go.

I installed the appropriate (x64) windows kits package and i'm able to use devcon.exe to find devices, remove devices, add devices, get their status etc..

When it comes to run a "devcon disable" on my particular device, devcon says the device does not exist.

Inspecting the device from Windows i was able to read the vendor id (0x065A)

(I tried the following commands in an administrator powershell window)

PS C:\Users\Hs> & "C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe" status USB\VID_065A*
USB\VID_065A&PID_A001\6&7998A49&0&3
    Name: USB Input Device
    Driver is running.
1 matching device(s) found.

All good

PS C:\Users\Hs> & "C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe" enable USB\VID_065A*
USB\VID_065A&PID_A001\6&7998A49&0&3                         : Enabled
1 device(s) are enabled.

Not very useful since the device was already working but at leas it confirms that devcon can see my device

now for the problematic part

PS C:\Users\Hs> & "C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe" disable USB\VID_065A*
USB\VID_065A&PID_A001\6&7998A49&0&3                         : Disable failed
No matching devices found.

Any idea about what i'm doing wrong?

fat

Posted 2019-06-27T16:08:12.513

Reputation: 111

Answers

1

If you want to do this in powershell without devcon, it is pretty simple:

Run get-pnpdevice to get a list of the devices. You are using the instancename in your example, this will allow you to use the friendly name. In the code below, just change where is says "USB Input Device" to be whatever the friendlyname of your barcode scanner is. Script can be reversed changing disable to enable.

Get-PnpDevice | Where-Object { $_.FriendlyName -match 'USB Input Device' } | Disable-PnpDevice -Confirm:$false

Narzard

Posted 2019-06-27T16:08:12.513

Reputation: 2 276

Getting "Disable-PnpDevice: Not supported" .. ` + CategoryInfo : NotImplemented: (Win32_PnPEntity...69AB8A&4&0000"):ROOT\cimv2\Win32_PnPEntity) [Disable-PnpDevic e], CimException`` – fat – 2019-06-27T16:50:12.807