Turn off and enable USB function
Turn off and enable USB function
First, turn on the USB function.
: USB-Enable@echo off:step1if exist C:\ Windows\ INF\ usbstor.inf (cls&goto: step2) else (cls&goto: step3): step2if exist C:\ Windows\ INF\ usbstor.inf.bak (cls&goto: exit) else (cls&goto: copy2): step3if exist C:\ Windows\ INF\ usbstor.inf.bak (cls&goto: copy1) else (cls&goto: exit) exit:copy1copy 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:copy2copy C:\ Windows\ INF\ usbstor.inf C:\ Windows\ INF\ usbstor.inf.bak:exitexit
Second, turn off the USB function.
:: USB-Disable@echo off:step1if exist C:\ Windows\ INF\ usbstor.inf.bak (cls&goto: step2) else (cls&goto: step3): step2if exist C:\ Windows\ INF\ usbstor.inf (cls&goto: del) else (cls&goto: reg): step3if exist C:\ Windows\ INF\ usbstor.inf (cls&goto: copy) else (cls&goto: exit) exit: regreg add "HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Services\ USBSTOR" / v Start / t Reg_dword / d 4 / f:copycopy C:\ Windows\ INF\ usbstor.inf C:\ Windows\ INF\ usbstor.inf.bakdel / s C:\ Windows\ INF\ usbstor.infreg add "HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Services\ USBSTOR" / v Start / t reg_dword / d 4 / f:deldel / s C:\ Windows\ INF\ usbstor.infreg add "HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Services\ USBSTOR" / v Start / t reg_dword / d 4 / f:exitExit
Third, sum up.
1. The script has been tested successfully on both window xp 7 and win10. If you need readonly to change the registry value to 1, you can test it if you are interested.
2. The script can be executed successfully after the GPO is issued, but the network exception execution is not successful due to some problems.