客户端Client installshield脚本

来源:互联网 发布:网络音乐播放器排行榜 编辑:程序博客网 时间:2024/05/16 13:52

//===========================================================================
//
//  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 CheckProgramRun(STRING);  
prototype CreateUninstallShortcut();   
BOOL    bvInstall,bvCancel;

//检查程序是否正在运行,如果正在运行将其关闭。
function   CheckProgramRun(szProgramName)//返回0,没有运行,1正在运行,
INT   nRet;  
HWND   nHwnd;  
begin  
 if(szProgramName   =   "")   then  
  nRet   =   0;  
  return   nRet;  
 endif;  
 //得到句柄  
 nHwnd   =   FindWindow("",szProgramName);  
 if(nHwnd   !=   NULL)   then        
  nRet   =   1;  
  //发消息关闭程序  
  //SendMessage(nHwnd,   WM_SYSCOMMAND,   SC_CLOSE,   0);  
 else  
  nRet   =   0;  
 endif;  
 return   nRet;  
end;   

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

    bvCancel = FALSE;
    bvInstall = FALSE;
   
    // Added in InstallShield 15 - Show an appropriate error message if
    // -removeonly is specified and the product is not installed.
    if( REMOVEONLY ) then
        Disable( DIALOGCACHE );
  szMsg = SdLoadString( IDS_IFX_ERROR_PRODUCT_NOT_INSTALLED_UNINST );
     SdSubstituteProductInfo( szMsg );
  MessageBox( szMsg, SEVERE );
  abort;
    endif;
  
    nSetupType = COMPLETE; 
    szDir = TARGETDIR;
    szName = "";
    szCompany = "";
    bLicenseAccepted = FALSE;

// 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;
   
    if (nResult = CANCEL) then
     bvCancel = TRUE;
     OnCanceling();
    endif;

Dlg_SdLicense2:
    szTitle = "";
    szOpt1 = "";
    szOpt2 = "";
    //{{IS_SCRIPT_TAG(License_File_Path)
    szLicenseFile = SUPPORTDIR ^ "license.rtf";
    //}}IS_SCRIPT_TAG(License_File_Path)
    //{{IS_SCRIPT_TAG(Dlg_SdLicense2)
    nResult = SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE );
    //}}IS_SCRIPT_TAG(Dlg_SdLicense2)
   
    if (nResult = CANCEL) then
     bvCancel = TRUE;
     OnCanceling();
    endif;       
   
    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_SdRegisterUser;
 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_SdRegisterUser;
   
    if (nResult = CANCEL) then
     bvCancel = TRUE;
     OnCanceling();
    endif;

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; 
       
         if (nResult = CANCEL) then
           bvCancel = TRUE;
          OnCanceling();
         endif;       
       
    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 = "";
    bvInstall = TRUE;
    //{{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 ) );
   
    if (nResult = CANCEL) then
     bvCancel = TRUE;
     OnCanceling();
    endif; 
 
    return 0;
end;

//---------------------------------------------------------------------------
// CreateUninstallShortcut
//
// This function create the shortcut for uninstalling.
//
// The CreateUninstallShortcut event is called directly by the user to create
// the uninstall shortcut and use before move data.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function CreateUninstallShortcut()
 string  szCmdLine,szTitle;
 LIST  lstPath;
 number  nReturn;
 string szResult,szTitleName;
begin      
 // For an InstallScript installation:
  szCmdLine = DISK1TARGET ^ "Setup.exe"; 
  LongPathToQuote(szCmdLine,TRUE); 
  // For an InstallScript MSI installation:
  //szCmdLine = 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, szCmdLine ); 
  LongPathToQuote( szCmdLine, TRUE );   
  
  szCmdLine = szCmdLine + " /M" + PRODUCT_GUID;
 endif; 


 GetSystemInfo(LANGUAGE,nReturn,szResult);
    StrRemoveLastSlash(TARGETDIR);
 ParsePath(szTitleName,TARGETDIR,FILENAME);
 if(nReturn = 2052) then 
  szTitle = "卸载9600客户端";
   AddFolderIcon(FOLDER_PROGRAMS^"Hikvision\\9600v1.1客户端", szTitle,szCmdLine, "","",0, "", REPLACE ); 
 endif;
 if(nReturn = 1033) then                           
  szTitle = "Uninstall Client";
  AddFolderIcon(FOLDER_PROGRAMS^"Hikvision\\Record_Client",szTitle,szCmdLine, "","",0, "", REPLACE ); 
 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
//增加删除菜单  
 if(bvCancel = FALSE) then
  if(bvInstall = TRUE) then 
   CreateUninstallShortcut();
  endif;
 endif;
end;

//---------------------------------------------------------------------------
// OnMaintUIBefore
//
// Maintenance UI Sequence - Before Move Data
//
// The OnMaintUIBefore event is called by OnShowUI when the setup is
// running in maintenance mode. By default this event displays UI that
// allows the end user to add or remove features, repair currently
// installed features or uninstall the application.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMaintUIBefore()
    number nResult, nType;
    string szTitle, szMsg;
begin
 
 // nType defaults to MODIFY.
 nType = MODIFY;

    //Initialize SQL
    OnSQLServerInitializeMaint();

// Beginning of UI Sequence
Dlg_Start:

    // Added in Version 9.5 - Support for REMOVEONLY option.
    if( !REMOVEONLY ) then
     // In standard mode show maintenance dialog
     Disable( BACKBUTTON );
     nType = SdWelcomeMaint( szTitle, szMsg, nType );
     Enable( BACKBUTTON );
        nResult = NEXT;
    else
        // Hide the initial progress dialog as otherwise the user can
        // click on it, and hide the MessageBox.
        Disable( DIALOGCACHE );

        // In RemoveOnly mode, set to remove.
        nType = REMOVEALL;
    endif;

 // Show Uninstall Confirmation Dialog
    if ( nType = REMOVEALL ) then
  nResult = MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO );
  if (nResult != IDYES ) then
           
            if( REMOVEONLY ) then
                // In REMOVEONLY mode, abort the setup.
                abort;
            else
                // In non-REMOVEONLY mode, redisplay the previous dialog.
       goto Dlg_Start;
            endif;

  endif;
 endif;

Dlg_SdFeatureTree:
 if ( nType = MODIFY ) then
  szTitle = "";
  szMsg = SdLoadString( SD_STR_COMPONENT_MAINT_MSG );
  nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, "", -1 );
  if ( nResult = BACK ) goto Dlg_Start;
    endif;

Dlg_ObjDialogs:
    nResult = ShowObjWizardPages( nResult );
    if ( ( nResult = BACK ) && ( nType != MODIFY ) ) goto Dlg_Start;
    if ( ( nResult = BACK ) && ( nType = MODIFY ) ) goto Dlg_SdFeatureTree;

 switch(nType)

        case REMOVEALL:
      
   // Ensure that all previously installed features are removed.
   FeatureRemoveAllInMediaAndLog();

            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );

        case REPAIR:
    
   // Changed for DevStudio 9, Disk1 files are now always updated when installed
   // so when running from ADDREMOVE we need to prevent these files from being
   // updated since this will result in files being updated that are locked by the setup.
   // Updating these files when running from ADDREMOVE should not be needed since updates
   // are not run directly from Add/Remove.
            if( ADDREMOVE ) then
                // Reinstall all previously installed features, except
                // disk1 features.
                FeatureUpdate( "" );
            else
                // Reinstall all previously installed features.
                FeatureReinstall();
            endif;

            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REPAIR ) );

        case MODIFY:
           
            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_MODIFY ) );

    endswitch;
 
end;

//---------------------------------------------------------------------------
// OnMaintUIAfter
//
// The OnMaintUIAfter event called by OnShowUI after the file transfer
// of the setup when the setup is running in maintenance mode. By default
// this event displays UI that informs the end user that the maintenance setup
// has been completed successfully.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMaintUIAfter()
     STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
    NUMBER bvOpt1, bvOpt2;
begin

    ShowObjWizardPages(NEXT);
   
    // Added - Version 9.5 - Use appropriate strings for complete
    // uninstall.
    if( REMOVEALLMODE ) then
        szTitle = SdLoadString(IFX_SDFINISH_REMOVE_TITLE);
        szMsg1 = SdLoadString(IFX_SDFINISH_REMOVE_MSG1);
       
        DeleteDir(TARGETDIR ,ROOT);           
        DeleteDir(FOLDER_APPLICATIONS^IFX_COMPANY_NAME,ONLYDIR);
        DeleteDir(FOLDER_PROGRAMS^"Hikvision\\9600v1.1客户端" ,ROOT); 
        DeleteDir(FOLDER_PROGRAMS^"Hikvision" ,ONLYDIR); 

    else
        szTitle = SdLoadString(IFX_SDFINISH_MAINT_TITLE);   
        szMsg1  = SdLoadString(IFX_SDFINISH_MAINT_MSG1);
    endif;

 szMsg2 = "";   
    szOpt1 = "";
    szOpt2 = "";
 bvOpt1   = FALSE;
    bvOpt2   = FALSE;   

    if ( BATCH_INSTALL ) then
     SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
    else   
        SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
    endif;
end;

//---------------------------------------------------------------------------
// OnMoving
//
// The OnMoving event is called as a result of the setup calling
// FeatureTransferData or FeatureMoveData. The event is called before any
// file transfer operations occur.
//---------------------------------------------------------------------------
function OnMoving()
    string szAppPath;
begin
// Un-comment the following script routine to set Logo Compliance Application Path
// TO DO: If your application's main executable file is in a subfolder of TARGETDIR then append this subfolder to szAppPath
//szAppPath = TARGETDIR;
//RegDBSetItem( REGDB_APPPATH, szAppPath );
//RegDBSetItem( REGDB_APPPATH_DEFAULT, szAppPath ^ IFX_PRODUCT_KEY );

   if (CheckProgramRun("控制客户端登录") = 1) then
  LaunchAppAndWait("", "taskkill /f /im csc.exe", LAAW_OPTION_HIDDEN|WAIT );     
  //Delay(2);
  //LaunchAppAndWait(TARGETDIR ^"uninstall_all.bat", "/qu",   WAIT);
  //MessageBox ("在执行操作之前,请先停止服务管理程序ServiceWatchdog.", SEVERE); 
  //abort;
 endif;
 
   if (CheckProgramRun("集中监控应用管理系统") = 1) then
  LaunchAppAndWait("", "taskkill /f /im csc.exe", LAAW_OPTION_HIDDEN|WAIT );     
  //Delay(2);
  //LaunchAppAndWait(TARGETDIR ^"uninstall_all.bat", "/qu",   WAIT);
  //MessageBox ("在执行操作之前,请先停止服务管理程序ServiceWatchdog.", SEVERE); 
  //abort;
 endif;
end;

 

0 0