InstallShield安装jdk并设置环境变量

时间:2022-12-12 19:48:50

1. 检查是否安装jdk

function OnBegin()
begin
Disable (BACKBUTTON);
if(!MAINTENANCE)then
SdLicense2 ("License ", "", "", SUPPORTDIR ^ "sn.txt", FALSE);
endif ;

// 获取注册表信息
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

// 检查是否安装jdk
if (RegDBKeyExist ("SOFTWARE\\JavaSoft\\Java Development Kit\\1.7.0_17") < 0) then
if(LaunchAppAndWait (SUPPORTDIR^"jdk-8u131-windows-i586.exe","", LAAW_OPTION_WAIT)<0)then
MessageBox ("您的系统没有安装 JDK 1.6.0_04 t! ", INFORMATION);
endif;
endif;
end;

2. 安装结束前设置环境变量

//安装结束之前,设置java_home环境变量

function OnEnd()
STRING szFeatureName;
STRING serviceTarget;
STRING szDocFile;
STRING szKey;
NUMBER nvType;
STRING svValue;
NUMBER nvSize;
begin

//检查是否已经安装jdk

szKey = "SOFTWARE\\JavaSoft\\Java Development Kit\\1.7.0_17";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

//如果已经安装则设置环境变量 java_home
if (RegDBKeyExist(szKey)=1) then//如果该注册表值存在
if(RegDBGetKeyValueEx(szKey,"JavaHome",nvType,svValue,nvSize)=0) then
szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
if(RegDBSetKeyValueEx(szKey, "JAVA_HOME", REGDB_STRING, svValue, -1)<0) then
MessageBox ("Javahome create failed, please set it manually!", SEVERE);
endif;
endif;
endif;