新建记事本 改后缀 *.bat
复制下内容
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit cd /d "%~dp0" @echo off echo 请输入jdk安装目录 set /p answer= wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%answer%" wmic ENVIRONMENT create name="CLASSPATH",username="<system>",VariableValue=".;%%JAVA_HOME%%\lib;%%JAVA_HOME%%\lib\tools.jar" wmic ENVIRONMENT where "name='PATH' and username='<system>'" set VariableValue="%path%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin;" echo 设置完成 按下任意键退出 pause