BAT 一键安装JDK

时间:2021-04-17 18:14:27

我使用的jkd 

jdk-7u79-windows-i586.exe --- 32位windos系统

jdk-7u80-windows-x64.exe  --- 64位windos系统


jdk必须与 bat文件同目录


@echo off

echo .
echo 开始执行-----------------------
if "%JAVA_HOME%"=="" (
echo 没有安装java需安装java
goto java
) else (
goto qidon
)
:java
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
rem 跳转到 32位系统安装
goto x86
)
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
rem 目录d:\<span style="font-family: Arial, Helvetica, sans-serif;">MIS</span>已存在,无需创建
goto AMD64
) else (
goto why
)
:x86
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
set myjdkpath=C:\Java\jdk1.7
echo **********************************************
echo.
echo 将要安装jdk
echo.
echo 安装请按任意键,退出直接关闭窗口
echo.
echo **********************************************
pause
echo.
echo 正在安装jdk,请不要执行其他操作
echo.
echo 请稍等,这个时间大约需要三、四分钟
echo.
start /WAIT jdk-7u79-windows-i586.exe /qn INSTALLDIR=C:\Java\jdk1.7
echo jdk安装完毕
set JAVA_HOME=C:\Java\jdk1.7
set PATH=%PATH%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin
set CLASSPATH=.;%%JAVA_HOME%%\lib\dt.jar;%%JAVA_HOME%%\lib\tools.jar
set RegV=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
reg add "%RegV%" /v "JAVA_HOME" /d "%JAVA_HOME%" /f
reg add "%RegV%" /v "Path" /t REG_EXPAND_SZ /d "%PATH%" /f
reg add "%RegV%" /v "CLASSPATH" /d "%CLASSPATH%" /f
mshta vbscript:msgbox("Java环境已成功注册!",64,"成功")(window.close)
#-Dfile.encoding=utf-8
goto end
:AMD64
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
set myjdkpath=C:\Java\jdk1.7
echo **********************************************
echo.
echo 将要安装jdk
echo.
echo 安装请按任意键,退出直接关闭窗口
echo.
echo **********************************************
pause
echo.
echo 正在安装jdk,请不要执行其他操作
echo.
echo 请稍等,这个时间大约需要三、四分钟
echo.
start /WAIT jdk-7u80-windows-x64.exe /qn INSTALLDIR=C:\Java\jdk1.7
echo jdk安装完毕
set JAVA_HOME=C:\Java\jdk1.7
set PATH=%PATH%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin
set CLASSPATH=.;%%JAVA_HOME%%\lib\dt.jar;%%JAVA_HOME%%\lib\tools.jar
set RegV=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
reg add "%RegV%" /v "JAVA_HOME" /d "%JAVA_HOME%" /f
reg add "%RegV%" /v "Path" /t REG_EXPAND_SZ /d "%PATH%" /f
reg add "%RegV%" /v "CLASSPATH" /d "%CLASSPATH%" /f
mshta vbscript:msgbox("Java环境已成功注册!",64,"成功")(window.close)
#-Dfile.encoding=utf-8
goto end
:why
echo 没有%PROCESSOR_ARCHITECTURE%系统的jdk安装版本
:end
echo 安装JDK完成
:qidon
set path=%cd%
set costPath=\cost_k3_wise
echo 按任意键启动COST_K3_WISE
pause
start cmd /k "cd/d %JAVA_HOME%\bin\ &&appletviewer %path%%costPath%\index.html"
echo 已持续完成,按任意键关闭------------------------------
echo .
pause