酷帥王子'blog-

java环境变量一键配置批处理(最好重启)

2021-9-7 21:39 作者:酷帥王子 | 黑盒网络渗透测试 |

@echo off
title Java环境变量设置 by Xu.J.Y
 mode con cols=60 lines=15
echo.
echo 正在检查并删除旧的Java环境变量设置...
echo.
rem 在环境变量path中,剔除掉变量java_home相关的字符
call set a=%%path:;%%java_home%%\jre\bin=%%
call set b=%%a:;%java_home%\jre\bin=%%
call set c=%%b:;%%java_home%%\bin=%%
call set d=%%c:;%java_home%\bin=%%
wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue=%d% >nul 2>nul

rem 如果有的话,先删除ClassPath 
wmic ENVIRONMENT where "name='ClassPath'" delete >nul 2>nul

rem 如果有的话,先删除JAVA_HOME
wmic ENVIRONMENT where "name='JAVA_HOME'" delete >nul 2>nul
cls
echo.
echo ===========================================================
echo          此批处理只需要安装JAVA后运行一次既可
echo ===========================================================
echo.
echo  你的Java安装在哪个盘?C D E F G H ...
echo.
set /p disk=请输入盘符:
echo.
echo 正在查看是否安装在默认路径
echo.
ping -n 2 127.0.0.1 >nul 2>nul
cls
set lu=""
setlocal enabledelayedexpansion
for /d %%i in ("%disk%:\Program Files\Java\jdk*") do set lu=%%i
if !lu!=="" (
echo.
echo 好吧,你太个性了~~修改了默认安装路径~~
echo.
echo 例如默认路径C:\Program Files\Java\jdk1.6.0_25
echo.
echo.
echo 现在就辛苦你手动输入jdk路径了^^.^^
echo.&set /p lu=路径:)
echo.
echo 安装路径:%lu%
ping -n 2 127.0.0.1 >nul 2>nul


wmic ENVIRONMENT create name="JAVA_HOME",username="<system>",VariableValue="%lu%"  >nul 2>nul

wmic ENVIRONMENT create name="CLASSPATH",username="<system>",VariableValue=".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar;" >nul 2>nul



wmic ENVIRONMENT where "name='PATH' and username='<system>'" set VariableValue="%d%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin" >nul 2>nul
echo.
echo 设置完成,请运行 检测环境变量设置是否成功.bat...
echo.
pause

rem 

文章作者:酷帥王子
文章地址:https://www.2k8.org:443/post-270.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

发表评论:



Powered by 酷帥王子

CopyRight © 2009-2016 酷帥王子'blog.  All rights reserved.