简体   繁体   English

如何通过命令提示符禁用和启用 usb 端口?

[英]How disable and enable usb port via command prompt?

How disable and enable usb port via command prompt?如何通过命令提示符禁用和启用 usb 端口? or using batch script?或使用批处理脚本? or using vb script in windows 7?或者在 windows 7 中使用 vb 脚本?

You can use batch which gives you a couple of options. 您可以使用批处理,它提供了几个选项。 You can edit the registry key to disable usb devices from being used 您可以编辑注册表项以禁用USB设备

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

To enable change value to 3 . 要将更改值设置为3

Or you can deny access to the files Usbstor.pnf and Usbstor.inf 或者您可以拒绝访问Usbstor.pnfUsbstor.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. user是您要拒绝访问的用户帐户。

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. 您还可以查看devcon命令。 Available freely on microsoft site, for win7+ windows. 适用于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: 1º-我们禁用了允许我们检测新的外部存储设备的功能:

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): 2º-我们删除了PC上安装的USB设备的所有驱动程序(这也将消除使用键盘和鼠标的可能性,但只是暂时的):

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: 3º-我们重新扫描连接的USB设备,以便Windows自动安装不同于外部存储设备的驱动程序(例如鼠标,键盘......),从而获得所需的结果:

devcon.exe rescan

4º- If we want to re-allow the use of external storage devices in our PC, we must use the command: 4º-如果我们想在我们的PC中重新允许使用外部存储设备,我们必须使用以下命令:

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

PD: Every command will need admin rights PD:每个命令都需要管理员权限

I use USBDeview.我使用 USBDeview。 See documentation and examples to use it.请参阅文档和示例以使用它。 Easy and works fine简单且工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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