@echo off&setlocal enabledelayedexpansion
:begin
cls
set/p input_path=C:\Program Files\Java\jdk1.6.0_35(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 where "name=‘JAVA_HOME‘ and username=‘<system>‘" set VariableValue="%input_path%"
::wmic ENVIRONMENT where "name=‘PATH‘ and username=‘<system>‘" set VariableValue="%PATH%;%%JAVA_HOME%%\bin"
::wmic ENVIRONMENT create name="CLASSPATH",username="<system>",VariableValue="%%JAVA_HOME%%\lib"
)
goto :eof
)
pause
goto :Eof
:error
echo 输入错误,请重新输入
pause
goto begin
ENVIRONMENT – 系统环境设置管理
::获取temp环境变量
wmic ENVIRONMENT where “name=’temp’” get UserName,VariableValue
::更改path环境变量值,新增e:\tools
wmic ENVIRONMENT where “name=’path’ and username=’<system>’” set VariableValue=”%path%;e:\tools”
::新增系统环境变量home,值为%HOMEDRIVE%%HOMEPATH%
wmic ENVIRONMENT create name=”home”,username=”<system>”,VariableValue=”%HOMEDRIVE%%HOMEPATH%”
::删除home环境变量
wmic ENVIRONMENT where “name=’home’” delete
原文地址:http://blog.csdn.net/cxx504659987/article/details/38399639