InstallShield使用——InstallScript的事件

 

1         InstallScript的事件

InstallScript MSI Preject项目中可以根据需要编写脚本控制安装过程,下面介绍几个重要的事件,事件分为三大类:Before Move Data(安装数据前)、Move Data(安装数据过程中)、After Move Data(安装数据后)。

1.1       Before Move Data

1.1.1   OnFirstUIBefore

在第一次安装时,在复制安装数据之前触发的事件,更改这个事件的脚本可自定义安装步骤。

下面给出InstallShield自身的脚本:

function OnFirstUIBefore()

    NUMBER nResult, nSetupType, nvSize, nUser;

    STRING szTitle, szMsg, szQuestion, svName, svCompany, szFile;

    STRING szLicenseFile;

    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 = SetupType(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;

从上面代码可以看出在没有安装类型界面时没有选择自定义安装时安装程序不会进入安装路径选择界面,这样用户不能自己选择安装路径,在Dlg_SetupType标签节中做一些修改,使不论怎么样都会进入安装路径选择界面,下面给出更改代码:

Dlg_SetupType:

    szTitle = "";

    szMsg   = "";

    nResult = SetupType(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;

              nResult = SdAskDestPath(szTitle, szMsg, INSTALLDIR, 0);

if (nResult = BACK) goto Dlg_SetupType

goto Dlg_SQL;

         else

              bCustom = TRUE;

        endif;

    endif;   

1.1.2   OnMaintUIBefore

在修改或卸载时,在复制安装数据之前触发的事件,例如安装程序在安装时添加了一个NT Service,在卸载时安装程序不会将将此服务反安装,这时就需要在这个事件中通过脚本LaunchApp (APPLICATION, “-uninstall”)手工删除服务。

1.1.3   OnSQLLogin

MS SQL SERVER数据库安装登录函数,InstallShield将此函数列出在InstallScript中应该是便于用户自行修改此函数。

1.2            Move Data

这个类型当中的事件一般来说不需要改动。

1.2.1   OnGeneratingMSIScript

Action(动作) LauchConditions之前执行;

1.2.2   OnGeneratedMSIScript

Action(动作) LauchConditions之后执行;

1.2.3   OnInstallFilesActionBefore

Action(动作) InstallFiles之前执行;

1.2.4   OnInstallFilesActionAfter

Action(动作) InstallFiles之后执行;

1.2.5   OnMoving

Action(动作) InstallInitialize之后执行;

1.2.6   OnMoved

Action(动作) GeneratedMSIScript之前执行;

1.3       After Move Data

1.3.1   OnFirstUIAfter

在第一次安装时,在复制安装数据之后触发的事件,例如有一个系统需要将安装路径设置FTP虚拟目录,如果在安装数据之前就设置的话,该路径不存在,无法设置成功,因此需要在这个事件中设置。

1.3.2   OnMaintUIAfter

在修改或卸载时,在修改或卸载数据之后触发的事件;

1.3.3   OnEnd

在安装完成之后触发的事件,即点击【完成】按钮后触发的事件,例如用附加数据库方式创建数据库时可在此事件中进行。

下一篇将介绍几个技术问题
原文地址:https://www.cnblogs.com/mm8413/p/1215270.html