一键加入环境变量

@echo
set JAVA_HOME=C:\Program Files (x86)\Java\jsdk
set CLASSPATH=%JAVA_HOME%\lib
pause
rem wmic ENVIRONMENT where "name='JAVA_HOME' and username=''" delete
rem wmic ENVIRONMENT where "name='CLASSPATH' and username=''" delete
wmic ENVIRONMENT where "name='JAVA_HOME'" delete
wmic ENVIRONMENT where "name='CLASSPATH'" delete
wmic ENVIRONMENT create name="JAVA_HOME",username="",VariableValue="%JAVA_HOME%"
wmic ENVIRONMENT create name="CLASSPATH",username="",VariableValue="%CLASSPATH%"
wmic ENVIRONMENT where "name='Path' and username=''" set VariableValue="%PATH%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin;"
pause
bat修改环境变量
@echo off&setlocal enabledelayedexpansion
:begin
cls
set/p input_path=环境变量的路径(例如:C:\Program Files\Java\jdk1.6.0_18(JDK的安装目录)):
if not defined input_path goto error
for,/f,"skip=4 tokens=1,2,*",%%a,in,('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v PATH'),do,(
echo 当前的环境变量为:
echo %%c
echo;
set/p yesno=是否确认将"%input_path%"添加到系统环境变量中去?[Y]/[N]
if /i "!yesno!"=="y" (
wmic ENVIRONMENT create name="JAVA_HOME",username="",VariableValue="%input_path%"
wmic ENVIRONMENT where "name='PATH' and username=''" set VariableValue="%PATH%;%%JAVA_HOME%%\bin"
wmic ENVIRONMENT create name="CLASSPATH",username="",VariableValue="%%JAVA_HOME%%\lib"
)
goto :eof
)
pause
goto :Eof        
:error
echo 输入错误,请重新输入
pause
goto begin
赞(0) 打赏
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

    暂无评论...