關閉和開啓USB功能

關閉和開啓USB功能網絡


一,開啓USB功能。
ide

::USB-Enable
@echo off
:step1
if exist C:\Windows\INF\usbstor.inf (cls&goto :step2) else (cls&goto :step3)

:step2
if exist C:\Windows\INF\usbstor.inf.bak (cls&goto :exit) else (cls&goto :copy2)

:step3
if exist C:\Windows\INF\usbstor.inf.bak (cls&goto :copy1) else (cls&goto :exit)
exit

:copy1
copy C:\Windows\INF\usbstor.inf.bak C:\Windows\INF\usbstor.inf 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 3 /f

:copy2
copy C:\Windows\INF\usbstor.inf C:\Windows\INF\usbstor.inf.bak

:exit
exit


2、關閉USB功能。
測試

::USB-Disable
@echo off
:step1
if exist C:\Windows\INF\usbstor.inf.bak (cls&goto :step2) else (cls&goto :step3)
:step2
if exist C:\Windows\INF\usbstor.inf (cls&goto :del) else (cls&goto :reg)
:step3
if exist C:\Windows\INF\usbstor.inf  (cls&goto :copy) else (cls&goto :exit)
exit 

:reg
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 4 /f

:copy
copy C:\Windows\INF\usbstor.inf C:\Windows\INF\usbstor.inf.bak
del /s C:\Windows\INF\usbstor.inf
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 4 /f

:del
del /s C:\Windows\INF\usbstor.inf
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 4 /f

:exit
Exit

三,總結一下spa

1,腳本在window xp 7和win10上都有測試執行成功,若是須要readonly須要將註冊表值改成1,有興趣的能夠測試一下。
it

2,腳本在GPO下發後生效能成功執行,有個別問題網絡異常執行不成功。class

相關文章
相關標籤/搜索