關閉和開啓USB功能

關閉和開啓USB功能


一,開啓USB功能。

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


二、關閉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

三,總結一下

1,腳本在window xp 7和win10上都有測試執行成功,如果需要readonly需要將註冊表值改爲1,有興趣的可以測試一下。

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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章