1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| @echo off
net session >nul 2>&1 if not "%errorLevel%" == "0" ( echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /b 2 ) rem 提升权限为管理员
echo 您确定要修复环境变量吗?重复修复可能导致错误! echo 任意键继续,若需退出,请直接关闭窗口。 pause>nul for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK" /v CurrentVersion 2^>nul') do set "a=%%b" for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK\%a%" /v JavaHome 2^>nul') do set "javapath=%%b"
echo 读取到的java环境地址为:%javapath%
set path_=%path%
echo 备份注册表中... echo WindowsRegistryEditorVer-sion5.00>backup.reg echo [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment]>>backup.reg echo "Path"=dword:%path%>>backup.reg
echo 正在修改环境变量... echo 写入环境变量"JAVA_HOME"... setx /m "JAVA_HOME" "%javapath% echo 写入环境变量"CLASSPATH"... setx /m "CLASSPATH" ".;%%JAVA_HOME%%\lib\dt\jar;%%JAVA_HOME%%\lib.tools.jar" echo 写入环境变量"Path"... setx /m "Path" "%_path%;%%JAVA_HOME%%\bin"
echo 程序结束! pause>nul
|