BAT-增加JAVA环境变量(WIN764位) - 疯狂delphi
BAT-增加JAVA环境变量(WIN764位)
相关资料:
1.http://www.jb51.net/article/52756.htm
2.http://blog.csdn.net/fireghost57/article/details/21103329
1.新建一个TXT,写入以下内容。
2.把TXT的名字改为BAT。
3.修改BAT中的各JAVA路径。
方法一:
1 @echo off2
3 ::设定环境变量
4 echo 设定环境变量
5 echo.
6 set "javahome=D:\Ruanjian\Java\jdk1.8.0_141"
7 set "classpath=.;"
8 set "pathpath=%%JAVA_HOME%%\BIN"
9
10 set "ev_javahome=JAVA_HOME"
11 set "ev_classpath=CLASSPATH"
12
13 ::检查JAVA_HOME
14 wmic ENVIRONMENT where "name=\'%ev_javahome%\'" get VariableValue|findstr /i /c:"VariableValue">nul&&(goto ENV_CREATEJAVAHOEM)
15 echo %env_path1%环境变量未创建
16 echo 创建环境变量
17 wmic ENVIRONMENT create name="%ev_javahome%",username="<system>",VariableValue="%javahome%"
18 :ENV_CREATEJAVAHOEM
19 echo %ev_javahome%环境变量已创建
20 echo.
21
22 ::检查CLASSPATH
23 wmic ENVIRONMENT where "name=\'%ev_classpath%\'" get VariableValue|findstr /i /c:"VariableValue">nul&&(goto ENV_CREATECLASSPATH)
24 echo %ev_classpath%环境变量未创建
25 echo 创建环境变量
26 wmic ENVIRONMENT create name="%ev_classpath%",username="<system>",VariableValue="%classpath%"
27 :ENV_CREATECLASSPATH
28 echo %ev_classpath%环境变量已创建
29 echo.
30
31 ::检查PATH中是否已添加%JAVA_HOME%\BIN
32 wmic ENVIRONMENT where "name=\'PATH\'" get VariableValue|findstr /i /c:"%pathpath%">nul&&(goto PATH_EXIST)
33 echo PATH环境变量中未添加: %pathpath%
34 set "set_val=%pathpath%;%PATH%"
35 wmic ENVIRONMENT where "name=\'PATH\' and username=\'<system>\'" set VariableValue="%set_val%"
36 :PATH_EXIST
37 echo PATH环境变量中已添加: %pathpath%
38
39 pause>nul
View Code
方法二:
1 @echo off2
3 echo 添加JAVA_HOME(亲试win764位)
4 set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
5 set evname=JAVA_HOME
6 set evpath=%javahome%
7 reg add "%regpath%" /v %evname% /d %evpath% /f
8
9 ::添加环境变量CLASSPATH(亲试win764位)
10 echo 添加CLASSPATH
11 set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
12 set evname=CLASSPATH
13 set evpath=%classpath%
14 reg add "%regpath%" /v %evname% /d %evpath% /f
15
16 ::删除环境变量JAVA_HOME(未测试)
17 @echo off
18 echo 删除java环境变量
19 set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
20 set evname=JAVA_HOME
21 reg delete "%regpath%" /v "%evname%" /f
22 pause>nul
23
24 ::是否存在(未测试)
25 @echo off
26 @set Path_=D:\Program Files
27 for,/f,"skip=4 tokens=1,2,*",%%a,in,(\'reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
28
29 Path\'),do,(
30 @set PathAll_=%%c
31 )
32 echo %PathAll_%|find /i "%Path_%" && set IsNull=true|| set IsNull=false
33 if not %IsNull%==true (
34 reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%PathAll_%;%Path_%"
35
36 /f
37 )
38 pause
View Code
以上是 BAT-增加JAVA环境变量(WIN764位) - 疯狂delphi 的全部内容, 来源链接: utcz.com/z/391428.html