open source guy
open source guy

Reputation: 2787

How disable and enable usb port via command prompt?

How disable and enable usb port via command prompt? or using batch script ? or using vb script in windows 7?

Upvotes: 5

Views: 115006

Answers (4)

diego bertotti
diego bertotti

Reputation: 1

I use USBDeview. See documentation and examples to use it. Easy and works fine. Now i'm using USBTreeView sieber webpage download link

Upvotes: 0

AngryCoder
AngryCoder

Reputation: 496

I have the same problem and I use a solution that takes the best of the two previous answers:

1º-We disable the functionality that allow us to detect new external storage devices:

reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "4" /f

2º-We remove all the drivers of USB devices installed on the PC (This will also eliminate the possibility of using keyboard and mouse, but only momentarily):

devcon.exe remove *USB*

3º- We re-scan the connected USB devices, so that Windows will automatically install the drivers of devices different than external storage (eg Mouse, keyboard ...), thus obtaining the desired result:

devcon.exe rescan

4º- If we want to re-allow the use of external storage devices in our PC, we must use the command:

reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "3" /f

PD: Every command will need admin rights

Upvotes: 1

anishsane
anishsane

Reputation: 20970

You can also have a look at devcon command. Available freely on microsoft site, for win7+ windows.

Upvotes: 2

Bali C
Bali C

Reputation: 31231

You can use batch which gives you a couple of options. You can edit the registry key to disable usb devices from being used

reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "4" /f

To enable change value to 3.

Or you can deny access to the files Usbstor.pnf and Usbstor.inf

cacls %windir%\Inf\Usbstor.pnf /d user
cacls %windir%\Inf\Usbstor.inf /d user

Where user is the user account that you want to deny access for.

To enable use

cacls %windir%\Inf\Usbstor.pnf /p user:R
cacls %windir%\Inf\Usbstor.inf /p user:R

Both commands will need admin rights.

Hope this helps

Upvotes: 11

Related Questions