您的位置:首页 > 其它

InstallShield2008脚本安装制作方法Setup

2015-03-12 09:17 330 查看
//===========================================================================

//

// 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"

//原型创建卸载快捷方式

prototype CreateUninstallShortcut();

//注册第三方DLL函数

prototype CallRegsterThirdDLL();

prototype CallUnRegsterThirdDLL();

//先安装的组件函数

prototype SetupPreCompontDLLorExe();

//---------------------------------------------------------------------------

// OnFirstUIBefore

// 第一个窗体之前 执行事件

// First Install UI Sequence - Before Move Data

//

// The OnFirstUIBefore event is called by OnShowUI when the setup is

// running in first install mode. By default this event displays UI allowing

// the end user to specify installation parameters.

//

// Note: This event will not be called automatically in a

// program...endprogram style setup.

//---------------------------------------------------------------------------

function OnFirstUIBefore()

number nResult, nLevel, nSize, nSetupType;

string szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;

string szName, szCompany, szTargetPath, szDir, szFeatures;

BOOL bLicenseAccepted;

begin

nSetupType = COMPLETE;

szDir = TARGETDIR;

szName = "";

szCompany = "";

bLicenseAccepted = FALSE;

//调用 先安装的组件函数

SetupPreCompontDLLorExe();

// Beginning of UI Sequence

Dlg_Start:

nResult = 0;

Dlg_SdWelcome:

szTitle = "";

szMsg = "";

//{{IS_SCRIPT_TAG(Dlg_SdWelcome)

nResult = SdWelcome( szTitle, szMsg );

//}}IS_SCRIPT_TAG(Dlg_SdWelcome)

if (nResult = BACK) goto Dlg_Start;

Dlg_SdLicense2:

szTitle = "";

szOpt1 = "";

szOpt2 = "";

//{{IS_SCRIPT_TAG(License_File_Path)

szLicenseFile = SUPPORTDIR ^ "Eula.rtf";

//}}IS_SCRIPT_TAG(License_File_Path)

//{{IS_SCRIPT_TAG(Dlg_SdLicense2)

nResult = SdLicense2Rtf( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted );

//}}IS_SCRIPT_TAG(Dlg_SdLicense2)

if (nResult = BACK) then

goto Dlg_SdWelcome;

else

bLicenseAccepted = TRUE;

endif;

Dlg_SdRegisterUser:

szMsg = "";

szTitle = "";

//{{IS_SCRIPT_TAG(Dlg_SdRegisterUser)

// nResult = SdRegisterUser( szTitle, szMsg, szName, szCompany );

//}}IS_SCRIPT_TAG(Dlg_SdRegisterUser)

if (nResult = BACK) goto Dlg_SdLicense2;

Dlg_SetupType2:

szTitle = "";

szMsg = "";

nResult = CUSTOM;

//{{IS_SCRIPT_TAG(Dlg_SetupType2)

nResult = SetupType2( szTitle, szMsg, "", nSetupType, 0 ); //完整/自定义安装

//}}IS_SCRIPT_TAG(Dlg_SetupType2)

if (nResult = BACK) then

goto Dlg_SdRegisterUser;

else

nSetupType = nResult;

if (nSetupType != CUSTOM) then

szTargetPath = TARGETDIR;

nSize = 0;

FeatureCompareSizeRequired( MEDIA, szTargetPath, nSize );

if (nSize != 0) then

MessageBox( szSdStr_NotEnoughSpace, WARNING );

goto Dlg_SetupType2;

endif;

endif;

endif;

Dlg_SdAskDestPath2:

if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType2;

szTitle = "";

szMsg = "";

if (nSetupType = CUSTOM) then

//{{IS_SCRIPT_TAG(Dlg_SdAskDestPath2)

nResult = SdAskDestPath2( szTitle, szMsg, szDir );

//}}IS_SCRIPT_TAG(Dlg_SdAskDestPath2)

TARGETDIR = szDir;

endif;

if (nResult = BACK) goto Dlg_SetupType2;

Dlg_SdFeatureTree:

if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2;

szTitle = "";

szMsg = "";

szFeatures = "";

nLevel = 2;

if (nSetupType = CUSTOM) then

//{{IS_SCRIPT_TAG(Dlg_SdFeatureTree)

nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel );

//}}IS_SCRIPT_TAG(Dlg_SdFeatureTree)

if (nResult = BACK) goto Dlg_SdAskDestPath2;

endif;

Dlg_SQLServer:

nResult = OnSQLServerInitialize( nResult );

if( nResult = BACK ) goto Dlg_SdFeatureTree;

Dlg_ObjDialogs:

nResult = ShowObjWizardPages( nResult );

if (nResult = BACK) goto Dlg_SQLServer;

Dlg_SdStartCopy2:

szTitle = "";

szMsg = "";

//{{IS_SCRIPT_TAG(Dlg_SdStartCopy2)

nResult = SdStartCopy2( szTitle, szMsg );

//}}IS_SCRIPT_TAG(Dlg_SdStartCopy2)

if (nResult = BACK) goto Dlg_ObjDialogs;

// Added in 11.0 - Set appropriate StatusEx static text.

SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) );

return 0;

end;

//定义 先安装的组件函数

function SetupPreCompontDLLorExe()

string szDotNetFx,SzLanguagePack;

string szAERRealVersion,szAERSpNumber;

string svNumber;

number nvType,nvSize;

string szOfficeLastProduct,svOfficeValue;

string szWinInstallerExe;

begin

//安装Window Installer 3.1 有哪些任兄知道的说一下谢谢!

//szWinInstallerExe=SUPPORTDIR ^ "WINDOWSINSTALLER-KB893803-V2-X86.EXE";

//RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

//if (RegDBKeyExist ("SOFTWARE//Classes//Msi.Package" ) < 0) then

// SdShowMsg("正在安装Window Installer 3.1,请稍候......",TRUE);

// LaunchAppAndWait(szWinInstallerExe,"",WAIT);

//endif;

//安装.NetFramework2.0

szDotNetFx = SUPPORTDIR ^ "dotnetfx.exe";

SzLanguagePack = SUPPORTDIR ^ "langpack.exe";

//szMDAC = SUPPORTDIR ^ "MDAC2.8.EXE"; //v1.1

RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

if (RegDBKeyExist ("SOFTWARE//Microsoft//.NETFramework//policy//v2.0" ) < 0) then

SdShowMsg("正在安装.Net2.0运行环境,请稍候......",TRUE);

LaunchAppAndWait(szDotNetFx,"",WAIT);

LaunchAppAndWait(SzLanguagePack,"",WAIT);

endif;

//安装MDAC2.8

//RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

//if (RegDBKeyExist ("SOFTWARE//Classes//MDACVer.Version.2.80" ) < 0) then

// LaunchAppAndWait(szMDAC,"",WAIT);

//endif;

//判断是否安装了ArcEngine9.2+SP3补丁包

szAERRealVersion="9.2";

szAERSpNumber="3";

nvSize=-1;

RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

if (RegDBGetKeyValueEx ("SOFTWARE//ESRI//ArcGIS Engine Runtime","RealVersion",nvType,svNumber,nvSize) < 0) then

MessageBox ("未安装ArcEngine9.2+SP3补丁包,请本安装完成后再安装!", SEVERE);

else

if(svNumber!=szAERRealVersion) then

MessageBox ("未安装ArcEngine9.2+SP3补丁包,请本安装完成后再安装!", SEVERE);

else

if(RegDBGetKeyValueEx ("SOFTWARE//ESRI//ArcGIS Engine Runtime","SPNumber",nvType,svNumber,nvSize) < 0) then

MessageBox ("未安装ArcEngine9.2+SP3补丁包,请本安装完成后再安装!", SEVERE);

else

if(svNumber!=szAERSpNumber) then

MessageBox ("未安装ArcEngine9.2+SP3补丁包,请本安装完成后再安装!", SEVERE);

endif;

endif;

endif;

endif;

//判断是否安装了Microsoft Office 2003 V11.0+SP2及以上版本

szOfficeLastProduct="11.0.7969.0"; //sp2 版本号

RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

if (RegDBKeyExist ("SOFTWARE//Microsoft//Office//11.0//Common//ProductVersion" ) < 0) then

MessageBox ("未安装Microsoft Office 2003 V11.0+SP2及以上版本,请本安装完成后再安装!", SEVERE);

else

if(RegDBGetKeyValueEx ("SOFTWARE//Microsoft//Office//11.0//Common//ProductVersion","LastProduct",nvType,svOfficeValue,nvSize) < 0) then

MessageBox ("未安装Microsoft Office 2003 V11.0+SP2及以上版本,请本安装完成后再安装!", SEVERE);

else

if(svOfficeValue<szOfficeLastProduct) then

MessageBox ("未安装Microsoft Office 2003 V11.0+SP2及以上版本,请本安装完成后再安装!", SEVERE);

endif;

endif;

endif;

end;

//注册第三方DLL函数

function CallRegsterThirdDLL()

string szDevExpress_Dll,szmicrosoft_mshtml_dll;

begin

//安装完后注册 DevExpress_Dll

szDevExpress_Dll = TARGETDIR ^ "//devexpress_dll//reg.bat";

//SdShowMsg("正在注册 DevExpress_Dll,请稍候......",TRUE);

//Delay(2);

if(LaunchAppAndWait(szDevExpress_Dll,"",WAIT)<0) then

endif;

//安装完后注册 microsoft_mshtml_dll

szmicrosoft_mshtml_dll = TARGETDIR ^ "//microsoft_mshtml_dll//reg.bat";

//SdShowMsg("正在注册 microsoft_mshtml_dll,请稍候......",TRUE);

//Delay(2);

if(LaunchAppAndWait(szmicrosoft_mshtml_dll,"",WAIT)<0) then

endif;

end;

//调用 卸载第三方组件

function CallUnRegsterThirdDLL()

string szDevExpress_Dll,szmicrosoft_mshtml_dll;

begin

//安装完后注册 DevExpress_Dll

szDevExpress_Dll = TARGETDIR ^ "//devexpress_dll//unreg.bat";

//SdShowMsg("正在注册 DevExpress_Dll,请稍候......",TRUE);

//Delay(2);

if(LaunchAppAndWait(szDevExpress_Dll,"",WAIT)<0) then

endif;

//LaunchApp(szDevExpress_Dll,"");

//安装完后注册 microsoft_mshtml_dll

szmicrosoft_mshtml_dll = TARGETDIR ^ "//microsoft_mshtml_dll//unreg.bat";

//SdShowMsg("正在注册 microsoft_mshtml_dll,请稍候......",TRUE);

//Delay(2);

//NOWAIT

if(LaunchAppAndWait(szmicrosoft_mshtml_dll,"",WAIT) <0) then

endif;

end;

//定义创建卸载快捷方式

function CreateUninstallShortcut()

string strCmdLine;

LIST lstPath;

begin

// For an InstallScript installation:

strCmdLine = DISK1TARGET ^ "Setup.exe";

// For an InstallScript MSI installation:

strCmdLine = UNINSTALL_STRING;

// The path has to be handled differently if you are running

// an InstallScript MSI installation on Windows 9X.

if (SYSINFO.WIN9X.bWin9X ) then

lstPath = ListCreate( STRINGLIST );

StrGetTokens( lstPath, UNINSTALL_STRING, "/" );

ListGetFirstString( lstPath, strCmdLine );

LongPathToQuote( strCmdLine, TRUE );

strCmdLine = strCmdLine + " /M" + PRODUCT_GUID;

endif;

// Create the shortcut.

AddFolderIcon(FOLDER_PROGRAMS ^ "XXXXX系统","卸载XXXXX系统V1.0",strCmdLine,"",TARGETDIR ^ "//remove.ico",0,"",REPLACE);

end;

//---------------------------------------------------------------------------

// OnFirstUIAfter

//

// First Install UI Sequence - After Move Data

//

// The OnFirstUIAfter event called by OnShowUI after the file transfer

// of the setup when the setup is running in first install mode. By default

// this event displays UI that informs the end user that the setup has been

// completed successfully.

//

// Note: This event will not be called automatically in a

// program...endprogram style setup.

//---------------------------------------------------------------------------

function OnFirstUIAfter()

STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2;

NUMBER bvOpt1, bvOpt2;

NUMBER bShowUpdateServiceDlg;

begin

ShowObjWizardPages(NEXT);

szTitle = "";

szMsg1 = "";

szMsg2 = "";

szOpt1 = "";

szOpt2 = "";

bvOpt1 = FALSE;

bvOpt2 = FALSE;

// Set this to true if you have the update service enabled, and if you want to check for updates.

// Note: the ISUS Starter Edition does not support checking for updates programatically. So,

// only set this to true if you have at least the ISUS Professional Edition.

bShowUpdateServiceDlg = FALSE;

//调用 创建卸载快捷方式

CreateUninstallShortcut();

//调用第三方组件 函数

CallRegsterThirdDLL();

//{{IS_SCRIPT_TAG(Dlg_SdDinishEx)

if ( BATCH_INSTALL ) then

SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );

else

// If the update service is enabled, show finish dialog that includes

// update check option.

if( bShowUpdateServiceDlg && ( ENABLED_ISERVICES & SERVICE_ISUPDATE ) ) then

if( SdFinishUpdateEx( szTitle, szMsg1, szMsg2, szOpt1, szOpt2, TRUE ) ) then

// Don't check for updates in silent mode.

if( MODE != SILENTMODE ) then

UpdateServiceCheckForUpdates( "", FALSE );

endif;

endif;

else

SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );

endif;

endif;

//}}IS_SCRIPT_TAG(Dlg_SdDinishEx)

end;

//---------------------------------------------------------------------------

// OnSetTARGETDIR

//

// OnSetTARGETDIR is called directly by the framework to initialize

// TARGETDIR to it's default value.

//

// Note: This event is called for all setups.

//---------------------------------------------------------------------------

function OnSetTARGETDIR()

number nId, nIgnore, nResult;

string szId, szTARGETDIR;

begin

// In maintenance mode the value of TARGETDIR is read from the log file.

if( MAINTENANCE ) then

return ISERR_SUCCESS;

endif;

// Set TARGETDIR to script default.

TARGETDIR = "<FOLDER_APPLICATIONS>//XXXX系统";

// Read TARGETDIR from the media.

nResult = MediaGetData( MEDIA, MEDIA_FIELD_TARGETDIR, nIgnore, szTARGETDIR );

// Use the TARGETDIR from the media if anything was read.

if( nResult >= ISERR_SUCCESS && StrLengthChars( szTARGETDIR ) ) then

TARGETDIR = szTARGETDIR;

endif;

// Customize the default TARGETDIR for multi-instance application.

// TODO: If you want something different customize the code below.

if( MAINT_OPTION = MAINT_OPTION_MULTI_INSTANCE && MULTI_INSTANCE_COUNT > 0) then

// Start with the current multi-instance count plus one.

nId = MULTI_INSTANCE_COUNT + 1;

// Find a unique TARGETDIR.

while( ExistsDir( TARGETDIR ) = EXISTS )

// Convert to string.

NumToStr( szId, nId );

// Update IFX_MULTI_INSTANCE_SUFFIX

IFX_MULTI_INSTANCE_SUFFIX = "_" + szId;

// Update TARGETDIR

TARGETDIR = TARGETDIR + IFX_MULTI_INSTANCE_SUFFIX;

// Update nId

nId = nId + 1;

endwhile;

endif;

end;

//---------------------------------------------------------------------------

// OnMoved

//

// The OnMoved event is called as a result of the setup calling

// FeatureTransferData or FeatureMoveData. The event is called when

// all file transfer operations are completed except for batch

// self-registration which is performed immediately after this event returns.

// During uninstallation this event sent after uninstallation is completed,

// therefore you should not modify system state in this event.

//---------------------------------------------------------------------------

function OnMoved()

begin

end;

//---------------------------------------------------------------------------

// OnSetUpdateMode

//

// OnSetUpdateMode is called directly by the framework to set the UPDATEMODE

// InstallShield system variable appropriately to control which UI events

// are called by OnShowUI.

//

// Note: This event is called for all setups.

//---------------------------------------------------------------------------

function OnSetUpdateMode()

number nIgnore, nMediaFlags, nInstalledVersion, nUpdateVersion, nResult;

string szVersion, szIgnore, szMsg;

begin

UPDATEMODE = FALSE; // Non-update mode by default.

// Added 11.5 - Don't set UPDATEMODE when running from Add/Remove

if( ADDREMOVE ) then

return ISERR_SUCCESS;

endif;

// Added 11.5 - Don't set UPDATEMODE when REMOVEONLY is specified

if( REMOVEONLY ) then

return ISERR_SUCCESS;

endif;

// Get the media flags.

MediaGetData( MEDIA, MEDIA_FIELD_MEDIA_FLAGS, nMediaFlags, szIgnore );

if( ! ( nMediaFlags & MEDIA_FLAG_UPDATEMODE_SUPPORTED ) ) then

return ISERR_SUCCESS; // Update mode not supported by the setup.

endif;

// TODO: If you are updating an application that was installed by a previous

// version of InstallShield, IFX_INSTALLED_VERSION will be empty, and

// VERSION_COMPARE_RESULT_NOT_INSTALLED will be returned by

// VerProductCompareVersions. Change the value of IFX_INSTALLED_VERSION (and

// IFX_INSTALLED_DISPLAY_VERSION) here based on application specific version

// information determined by the setup. Only do this if IFX_INSTALLED_VERSION

// is empty.

//if ( !StrLengthChars( IFX_INSTALLED_VERSION ) && MAINTENANCE ) then

// IFX_INSTALLED_VERSION = "X.XX.XXX";

// IFX_INSTALLED_DISPLAY_VERSION = IFX_INSTALLED_VERSION;

//endif;

// Verify that the installed version is valid.

if( !StrLengthChars( IFX_INSTALLED_VERSION ) && MAINTENANCE ) then

// If this error occurs, IFX_INSTALLED_VERSION needs to be set manually.

szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NO_INSTALLED_VERSION );

MessageBox( szMsg, SEVERE );

abort;

endif;

// Verify that the product version is valid.

if( !StrLengthChars( IFX_PRODUCT_VERSION ) ) then

// If this error occures, IFX_PRODUCT_VERSION was not initialized correctly.

szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NO_PRODUCT_VERSION );

MessageBox( szMsg, SEVERE );

abort;

endif;

// Do the version comparison.

nResult = VerProductCompareVersions();

// Make sure that valid data was returned by VerProductCompareVersions

if( nResult < ISERR_SUCCESS ) then

szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_VERSION_COMPARE_FAILURE );

MessageBox( szMsg, SEVERE );

abort;

endif;

// Set update mode if this is a differential media or the product is already installed and the versions do not match.

UPDATEMODE = ( nMediaFlags & MEDIA_FLAG_FORMAT_DIFFERENTIAL || ( MAINTENANCE && ( nResult != VERSION_COMPARE_RESULT_SAME ) ) );

end;

//---------------------------------------------------------------------------

// OnCheckMediaPassword

//

// Displays a password dialog if the media is password protected.

//

// Note: This event is called for all setups.

//---------------------------------------------------------------------------

function OnCheckMediaPassword()

string szResult, szMsg;

BOOL bValidated;

begin

// Check whether the setup author selected this option.

if( !SHOW_PASSWORD_DIALOG ) then;

return ISERR_SUCCESS;

endif;

// Check whether the password has been specified previously.

LogReadCustomString( MEDIA_PASSWORD_KEY, szResult );

if( FeatureValidate( MEDIA, "", szResult ) == 0 ) then

return ISERR_SUCCESS;

endif;

// "Back" button should be disabled.

Disable( BACKBUTTON );

// Attempt to validate the media.

bValidated = FALSE;

// Loop until the password is validated.

while( !bValidated )

// Prompt for password.

if( EnterPassword( "", "", szResult ) < ISERR_SUCCESS ) then

abort; // Failed to display password dialog

endif;

// Attempt to validate the media.

if( FeatureValidate( MEDIA, "", szResult ) == 0 ) then

// Store the media password for maintenance mode.

LogWriteCustomString( MEDIA_PASSWORD_KEY, szResult );

bValidated = TRUE;

else

szMsg = SdLoadString( IDS_IFX_ERROR_INVALID_MEDIA_PASSWORD );

MessageBox( szMsg, INFORMATION );

endif;

endwhile;

// Enable "Back" button.

Enable( BACKBUTTON );

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()

begin

end;

//---------------------------------------------------------------------------

// OnUninstall

//

// The OnUninstall event is called when the setup is run with the -uninst

// switch, in this case this is the only event that will be called.

//---------------------------------------------------------------------------

function OnUninstall()

string szIgnore, szMsg;

number nResult;

BOOL bOpt1, bOpt2;

begin

// Hide the initial progress dialog.

Disable( DIALOGCACHE );

// Show Uninstall Confirmation Dialog

if( MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO ) != IDYES ) then

abort;

endif;

//调用反安装函数

CallUnRegsterThirdDLL();

// Remove all features.

FeatureRemoveAllInMediaAndLog();

// Added in 11.0, disable the cancel button during uninstall.

if( REMOVEALLMODE ) then

Disable( CANCELBUTTON );

endif;

// Added in 11.0 - Set appropriate StatusEx static text.

// Moved in 12.1 - Set before calling Enable( STATUSEX ) to ensure proper product name updating.

SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );

// Show Status

SetStatusWindow( 0, "" );

Enable( STATUSEX );

StatusUpdate( ON, 100 );

// Uninstall

nResult = FeatureTransferData( MEDIA );

// Handle move data error and abort if error occured.

if( nResult < ISERR_SUCCESS ) then

OnComponentError();

abort;

endif;

// Disable Status

Disable( STATUSEX );

// Show final dialog.

if ( BATCH_INSTALL ) then

SdFinishReboot( SdLoadString(IFX_SDFINISH_REMOVE_TITLE), SdLoadString(IFX_SDFINISH_REMOVE_MSG2), SYS_BOOTMACHINE, "", 0 );

else

SdFinish( SdLoadString(IFX_SDFINISH_REMOVE_TITLE), SdLoadString(IFX_SDFINISH_REMOVE_MSG1), "", "" , "", bOpt1 , bOpt2 );

endif;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐