bat脚本自动下载并安装jdk,自动设置java环境变量
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" bitsadmin /transfer test /download /priority normal "https://soft.xitongxz.net/202204/jdk-11.0.15_windows-x64_bin.exe" "C:\jdk-11.0.15_windows-x64_bin.exe" @echo off Setlocal enabledelayedexpansion @REM vscode中自动开启延迟环境变量扩展, %~d0 cd %~dp0 @REM dir echo install jdk -->start install jdk @REM dir @REM start /wait "C:\jdk-11.0.15_windows-x64_bin.exe" /quiet "C:\jdk-11.0.15_windows-x64_bin.exe" /quiet @REM C:\Program Files\Java\jdk-11.0.15 echo 提取系统级变量path set key="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" for /F "skip=2 tokens=3" %%i IN ('reg query %key% /v "Path"') do ( echo 原始Path ======= %%i set temppath=%%i ) echo 设置jdk环境变量 setx /M JAVA_HOME "C:\Program Files\Java\jdk-11.0.15" setx /M path "%temppath%%%JAVA_HOME%%\bin" setx /M classpath ".;%%JAVA_HOME%%\lib\dt.jar;%%JAVA_HOME%%\lib\tools.jar" pause
win11(64位)测试ok 其他系统未测试