@echo off
SETLOCAL
ENABLEDELAYEDEXPANSION
for /f "tokens=2* delims= " %%i in
('reg query "HKLM\Software\JavaSoft\Java Development Kit" /s ^|
find /I
"JavaHome"') do (
echo 找到目录 %%j
set /p isOK=该目录是不是JDK^(Java
Development Kit^)的安装目录?[Y/N]
if /I "!isOK!"=="Y" (
call :setenv "%%j"
goto :eof
)
)
echo 找不到JDK(Java Development
Kit)安装目录,请手动输入(可以通过右击窗口粘贴)。
:input
set javapath="null"
set /p javapath=?:
if exist "%javapath:"=%" (
call :setenv "%javapath:"=%"
) else (
echo 目录不存在,请检查并重新输入。
goto :input
)
goto :eof
:setenv
echo.
echo 设置Path
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
Path | find /I "%~1\bin" >nul
if %errorlevel% EQU 0 (
echo Path中已存在"%~1\bin",不进行添加
) else (
for /f "skip=2 tokens=2* delims= "
%%m in ('reg query
"HKLM\SYSTEM\ControlSet001\Control\Session
Manager\Environment" /v Path') do
(
echo Path中无"%~1\bin",进行添加
reg add
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
Path /t
REG_EXPAND_SZ /d "%~1\bin;%%n"
/f
)
)
echo.
echo 设置ClassPath
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath >nul 2>nul
if %errorlevel% EQU 1 (
echo
ClassPath不存在,新建并设置为".;%~1\lib\dt.jar;%~1\lib\tools.jar"
reg add
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath /t REG_SZ /d
".;%~1\lib\dt.jar;%~1\lib\tools.jar" /f
echo 按任意键退出...
pause >nul
goto :eof
)
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath | find /I "%~1\lib
\tools.jar"
>nul
if %errorlevel% EQU 0 (
echo
ClassPath中已存在"%~1\lib\tools.jar",不进行添加
) else (
for /f "skip=2 tokens=2* delims= "
%%m in ('reg query
"HKLM\SYSTEM\ControlSet001\Control\Session
Manager\Environment" /v ClassPath')
do (
echo
ClassPath中无"%~1\lib\tools.jar",进行添加
reg add
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath /t
REG_SZ /d "%~1\lib\tools.jar;%%n"
/f
)
)
echo.
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath | find /I "%~1\lib
\dt.jar" >nul
if %errorlevel% EQU 0 (
echo
ClassPath中已存在"%~1\lib\dt.jar",不进行添加
) else (
for /f "skip=2 tokens=2* delims= "
%%m in ('reg query
"HKLM\SYSTEM\ControlSet001\Control\Session
Manager\Environment" /v ClassPath')
do (
echo
ClassPath中无"%~1\lib\dt.jar",进行添加
reg add
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath /t
REG_SZ /d "%~1\lib\dt.jar;%%n"
/f
)
)
echo.
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath | find /I ".;" >nul
if %errorlevel% EQU 1 (
reg query
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath | find /I ";."
>nul
)
if %errorlevel% EQU 0 (
echo ClassPath中已存在".",不进行添加
) else (
for /f "skip=2 tokens=2* delims= "
%%m in ('reg query
"HKLM\SYSTEM\ControlSet001\Control\Session
Manager\Environment" /v ClassPath')
do (
echo ClassPath中无".",进行添加
reg add
"HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
ClassPath /t
REG_SZ /d ".;%%n" /f
)
)
echo.
echo 按任意键退出...
pause >nul
goto :eof