今天研究了一下用InstallShield12打包,顺便把代码给大家共享一下,
希望对刚接触的朋友有所帮助(我也是刚接触的),程序包括安装JDK,TOMCATE等等,
//===========================================================================
//
// File Name: Setup.rul
//
// Description: Blank setup main script file
//
// Comments: Blank setup is an empty setup project. If you want to
// create a new project via. step-by step instructions use the
// Project Assistant.
//
//===========================================================================
// Included header files ----------------------------------------------------
#include "ifx.h"
// Note: In order to have your InstallScript function executed as a custom
// action by the Windows Installer, it must be prototyped as an
// entry-point function.
// The keyword export identifies MyFunction() as an entry-point function.
// The argument it accepts must be a handle to the Installer database.
/* export prototype MyFunction(HWND); */
//---------------------------------------------------------------------------
// OnFirstUIBefore
//
// The OnFirstUIBefore event is called by the framework when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//---------------------------------------------------------------------------
function OnFirstUIBefore()
NUMBER nResult, nSetupType, nvSize, nUser;
STRING szTitle, szMsg, szQuestion, svName, svCompany, szFile;
STRING szLicenseFile,szJDK;
LIST list, listStartCopy;
BOOL bCustom;
begin
// TO DO: if you want to enable background, window title, and caption bar title
// SetTitle( @PRODUCT_NAME, 24, WHITE );
// SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION );
// Enable( FULLWINDOWMODE );
// Enable( BACKGROUND );
// SetColor(BACKGROUND,RGB (0, 128, 128));
SHELL_OBJECT_FOLDER = @PRODUCT_NAME;
nSetupType = TYPICAL;
Dlg_SdWelcome:
szTitle = "欢迎使用教育收费系统!";
szMsg = "";
nResult = SdWelcome(szTitle, szMsg);
if (nResult = BACK) goto Dlg_SdWelcome;
szTitle = "";
svName = "";
svCompany = "";
Dlg_SdCustomerInformation:
nResult = SdCustomerInformation(szTitle, svName, svCompany, nUser);
if (nResult = BACK) goto Dlg_SdWelcome;
Dlg_SetupType:
szTitle = "选择安装类型";
szMsg = "";
nResult = SetupType2(szTitle, szMsg, "", nSetupType, 0);
if (nResult = BACK) then
goto Dlg_SdCustomerInformation;
else
nSetupType = nResult;
if (nSetupType != CUSTOM) then
nvSize = 0;
FeatureCompareSizeRequired(MEDIA, INSTALLDIR, nvSize);
if (nvSize != 0) then
MessageBox(szSdStr_NotEnoughSpace, WARNING);
goto Dlg_SetupType;
endif;
bCustom = FALSE;
goto Dlg_SQL;
else
bCustom = TRUE;
endif;
endif;
Dlg_SdAskDestPath:
nResult = SdAskDestPath(szTitle, szMsg, INSTALLDIR, 0);
if (nResult = BACK) goto Dlg_SetupType;
Dlg_SdFeatureTree:
szTitle = "";
szMsg = "";
if (nSetupType = CUSTOM) then
nResult = SdFeatureTree(szTitle, szMsg, INSTALLDIR, "", 2);
if (nResult = BACK) goto Dlg_SdAskDestPath;
endif;
Dlg_SQL:
nResult = OnSQLLogin( nResult );
if( nResult = BACK ) then
if (!bCustom) then
goto Dlg_SetupType;
else
goto Dlg_SdFeatureTree;
endif;
endif;
Dlg_SdStartCopy:
szTitle = "";
szMsg = "";
listStartCopy = ListCreate( STRINGLIST );
//The following is an example of how to add a string(svName) to a list(listStartCopy).
//eg. ListAddString(listStartCopy,svName,AFTER);
nResult = SdStartCopy( szTitle, szMsg, listStartCopy );
ListDestroy(listStartCopy);
if (nResult = BACK) then
goto Dlg_SQL;
endif;
// setup default status
Enable(STATUSEX);
return 0;
end;
//---------------------------------------------------------------------------
// OnEnd
//
// The OnEnd event is called at the end of the setup. This event is not
// called if the setup is aborted.
//---------------------------------------------------------------------------
function OnEnd()
STRING szJDK,szTOMCAT,szKey,svJdk,svTomcat,szROOT;
STRING szDir,szFolder,szCmdLine,sDel;
NUMBER nvSize,nType;
begin
MessageBox("所有程序准备就绪,正在准备安装必备的其他程序及配置服务器。。。",INFORMATION);
MessageBox ("接下来系统将安装必要的JDK外部程序 ...如果系统提示已经安装JDK则点击取消进行下一步安装。", INFORMATION);
szJDK = TARGETDIR ^ "jdk-1_5_0_04.exe";
if (LaunchAppAndWait (szJDK, "", WAIT) < 0) then
MessageBox ("不能加载JDK程序 "+ szJDK +".",SEVERE);
endif;
DeleteFile (szJDK);
MessageBox ("接下来系统将安装必要的Tomcat外部程序 ...如果系统提示已经安装tomcat则点击取消进行下一步安装。", INFORMATION);
szTOMCAT = TARGETDIR ^ "tomcat-5.0.27.exe";
if (LaunchAppAndWait (szTOMCAT, "", WAIT) < 0) then
MessageBox ("不能加载Tomcat程序 "+ szTOMCAT +".",SEVERE);
endif;
DeleteFile (szTOMCAT);
// 搜寻 JDK 安装的路径
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szKey = "SOFTWARE\\JavaSoft\\Java Development Kit\\1.5";
nType = REGDB_STRING;
svJdk = "";
if(RegDBGetKeyValueEx(szKey, "JavaHome", nType, svJdk, nvSize) < 0) then
MessageBox ("查找 JDK 路径失败,", SEVERE);
endif;
MessageBox("JDK 安装的路径:"+svJdk,INFORMATION);
// 搜寻 tomcat 安装的路径
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szKey = "SOFTWARE\\Apache Software Foundation\\Tomcat\\5.0";
nType = REGDB_STRING;
svTomcat = "";
if(RegDBGetKeyValueEx(szKey, "InstallPath", nType, svTomcat, nvSize) < 0) then
MessageBox ("查找 Tomcat 路径失败,", SEVERE);
endif;
MessageBox("tomcat 安装的路径:"+svTomcat,INFORMATION);
//sDel=svTomcat ^ "webapps\\ROOT\\index.jsp";
//MessageBox("路径:"+sDel,INFORMATION);
//DeleteFile (svTomcat ^ "webapps\ROOT\index.jsp");
MessageBox ("接下来解压程序文件 ...", INFORMATION);
szROOT = TARGETDIR ^ "ROOT.exe";
if (LaunchAppAndWait (szROOT, "", WAIT) < 0) then
MessageBox ("不能加载程序文件 "+ szROOT +".",SEVERE);
endif;
DeleteFile (szROOT);
//附加程序文件
//szDir = svTomcat + "\\webapps\\ROOT";
//MessageBox("正在准备附加程序文件。。。",INFORMATION);
//szFolder = TARGETDIR + "\\ROOT";
//CreateDir(szDir);
// if(XCopyFile(szFolder^"*.*",szDir,INCLUDE_SUBDIR)<0)
// then
// MessageBox("程序文件附加失败!",SEVERE);
// else
// MessageBox("程序文件已经附加成功!",INFORMATION);
// endif;
MessageBox("正在准备启动Tomcat....",INFORMATION);
// 准备启动TOMCAT服务器
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szKey = "SOFTWARE\\Apache Software Foundation\\Tomcat\\5.0";
nType = REGDB_STRING;
svTomcat = "";
if(RegDBGetKeyValueEx(szKey, "InstallPath", nType, svTomcat, nvSize) < 0) then
MessageBox ("查找 Tomcat 路径失败,系统不能继续安装", SEVERE);
endif;
TARGETDIR = svTomcat + "\\bin\\tomcat5.exe";
LaunchAppAndWait (TARGETDIR,"",NOWAIT); //启动tomcat
MessageBox("Tomcat 已经启动成功!正在准备打开网页....",INFORMATION);
//准备打开浏览器
szCmdLine = "http://LocalHost:8090/index.jsp";
if (LaunchApp(PROGRAMFILES