查询注册表是否禁用USB
@echo off
set "str=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR"
for /f "tokens=2*" %%a in ('reg query "%str%" /v Start 2^>nul') do set "a=%%b"
if "%a%"=="0x4" ( echo USB已经禁用 >>USB已禁用) else ( echo USB未禁用>>USB未禁用)
禁用USB
@echo off
COPY %WINDIR%\inf\usbstor.inf %WINDIR%\usbstor.inf
COPY %WINDIR%\inf\usbstor.PNF %WINDIR%\usbstor.PNF
DEL %WINDIR%\inf\usbstor.inf
DEL %WINDIR%\inf\usbstor.PNF
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 4 /f
echo on
解除禁用
@echo off
COPY %WINDIR%\usbstor.inf %WINDIR%\inf\usbstor.inf
COPY %WINDIR%\usbstor.PNF %WINDIR%\inf\usbstor.PNF
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t reg_dword /d 3 /f
echo on
########################################################################################
5.7更新 结果可以上传到共享目录
@echo off
rem 隐藏启动批处理运行过程中的黑框
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
date /t >>\\共享目录IP地址\usb\result.txt
time /t >>\\共享目录IP地址\usb\result.txt
echo 主机名:hostname >>\\共享目录IP地址\usb\result.txt
echo 登陆账户:%username% >>\\共享目录IP地址\usb\result.txt
set "str=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR"
for /f "tokens=2*" %%a in ('reg query "%str%" /v Start 2^>nul') do set "a=%%b"
if "%a%"=="0x4" ( echo USB已经禁用 >>\\共享目录IP地址\usb\result.txt) else ( echo USB启用 >>\\共享目录IP地址\usb\result.txt)
echo IP地址是: >>\\共享目录IP地址\usb\result.txt
ipconfig | find /i "ip" >>\\共享目录IP地址\usb\result.txt
echo =========================================================== >>\\共享目录IP地址\usb\result.txt
exit