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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13267236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:02:48  来源:igfitidea点击:

How disable and enable usb port via command prompt?

windowsbatch-filevbscript

提问by open source guy

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

如何通过命令提示符禁用和启用 USB 端口?或使用批处理脚本?或在 Windows 7 中使用 vb 脚本?

回答by Bali C

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.pnfand Usbstor.inf

或者您可以拒绝访问文件Usbstor.pnfUsbstor.inf

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

Where useris 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

希望这可以帮助

回答by anishsane

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

你也可以看看devcon命令。可在 microsoft 网站上免费获得,适用于 win7+ windows。

回答by AngryCoder

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

我有同样的问题,我使用的解决方案充分利用了前两个答案:

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

1o-我们禁用允许我们检测新外部存储设备的功能:

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

2o-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):

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

devcon.exe remove *USB*

3o- 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:

3o- 我们重新扫描连接的USB设备,这样Windows会自动安装不同于外部存储设备的驱动程序(例如鼠标,键盘......),从而获得预期的结果:

devcon.exe rescan

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

4o- 如果我们想重新允许在我们的 PC 中使用外部存储设备,我们必须使用命令:

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

PD: Every command will need admin rights

PD:每个命令都需要管理员权限