%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
注:复制下来保存为.bat即可,如乱码,另存为ANSI格式即可