简体   繁体   中英

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?

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

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

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

I use USBDeview. See documentation and examples to use it. Easy and works fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM