InstallShield 打包需要的几段脚本代码

在setup.Rul中的脚本:

//===========================================================================
//
//  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"
#include "script.rul"


prototype CreateUninstallShortcut(); //放在#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,szTargetdir;
    STRING szLicenseFile;
    LIST list, listStartCopy;
 BOOL bCustom;
begin      
    
     InsrtInstallCrysalRpeort();
   
 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_SdLicense:
 nResult = DialogShowSdLicense();
    if (nResult = BACK) goto Dlg_SdWelcome;

Dlg_SdCustomerInformation:
 nResult = SdCustomerInformation(szTitle, svName, svCompany, nUser);
 if (nResult = BACK) goto Dlg_SdLicense;
 

Dlg_SdAskDestPath: //改变路径   
   nResult =SdAskDestPath(szTitle, szMsg,INSTALLDIR,0);
   //nResult =SdAskDestPath2(szTitle, szMsg,INSTALLDIR);
   //DialogShowSdAskDestPath_ERP( );
    if (nResult = BACK) goto Dlg_SdCustomerInformation;    
Dlg_SQL:
    nResult = OnSQLLogin( nResult );
    if( nResult = BACK ) then
      goto Dlg_SdAskDestPath;   
    endif;

Dlg_SdStartCopy:    //当前位置 ,开始复制文件
    szTitle = "";
    szMsg   = "";
    listStartCopy = ListCreate( STRINGLIST );
   
    ListDestroy(listStartCopy);
 
 if (nResult = BACK) then
     goto Dlg_SQL;
    endif;

    Enable(STATUSEX); 
     CreatFont();
    return 0;      
   
  
end;              

//---------------------------------------------------------------------------
// OnBegin
//
// The OnBegin event is called directly by the framework after the setup
// initializes.
//---------------------------------------------------------------------------
function OnBegin()  
   STRING svResult,szProg,szCmdLine ;
begin
 // TO DO: you may change default non-UI setting, for example
 //
 // You may also perform your custom initialization steps, check requirements, etc.  
              
    

end;
//---------------------------------------------------------------------------
// OnMaintUIBefore
//
// The OnMaintUIBefore event is called by the framework 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.
//---------------------------------------------------------------------------
function OnMaintUIBefore()
NUMBER nResult,nLevel,nType;
STRING szTitle,szMsg,svDir,szComponents,svResult,szCaption,szTargetPath;
begin


nType = REPAIR;

Dlg_Start:
Disable(BACKBUTTON);
nResult = SdWelcomeMaint(szTitle, szMsg, nType);
Enable(BACKBUTTON);

Dlg_SdComponentTree:
if (nResult = MODIFY) then
szTitle = "";
szMsg = "";
svDir = TARGETDIR;
szComponents = "";
nLevel = 2;
nResult = SdComponentTree(szTitle, szMsg, svDir, szComponents, nLevel);
if (nResult = BACK) goto Dlg_Start;
//setup default status
SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100);

elseif (nResult = REMOVEALL) then
svResult = SdLoadString(IFX_MAINTUI_MSG);
szCaption = SdLoadString(IFX_ONMAINTUI_CAPTION);
nResult = SprintfBox(MB_OKCANCEL,szCaption,"%s",svResult);
if (nResult = IDCANCEL) then
goto Dlg_Start;
elseif(nResult = IDOK) then
// setup default status
SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100);

//-->Remove all components
ComponentRemoveAll();
 
 
/////////////////////////////////////////
///删除指定文件夹
//////////////////////////////////////////////
szTargetPath=  PROGRAMFILES ^"Constructor";
DeleteProgramFolder(szTargetPath); 
///////////////////////////////////////////////   

endif;
elseif (nResult = REPAIR) then
// setup default status
 SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100);

//-->Reinstall Logged Components
ComponentReinstall(); 

endif;


DeleteDir(TARGETDIR,ALLCONTENTS);
DeleteDir(TARGETDIR,ONLYDIR);

end;
//---------------------------------------------------------------------------
// OnFirstUIAfter
//
// The OnFirstUIAfter event called by the framework 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.
//---------------------------------------------------------------------------
function OnFirstUIAfter()
    STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;
    NUMBER bOpt1, bOpt2;
begin 

    ExFn_CreateUnInstall("create");   
    
 Disable(STATUSEX);   
   
 bOpt1  = FALSE;
 bOpt2  = FALSE;
 szMsg1 = SdLoadString(IFX_SDFINISH_MSG1);
 SdFinishEx(szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2);
 
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 
InsrtDotNetFramework();
end;
//---------------------------------------------------------------------------
// OnMaintUIAfter
//
// The OnMaintUIAfter event called by the framework 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.
//---------------------------------------------------------------------------
function OnMaintUIAfter()
 STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;
 NUMBER bOpt1, bOpt2;
begin

 Disable(STATUSEX);
  
    
   
 bOpt1   = FALSE;
 bOpt2   = FALSE;
   
 // 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);
    else
        szTitle = SdLoadString(IFX_SDFINISH_MAINT_TITLE);   
        szMsg1  = SdLoadString(IFX_SDFINISH_MAINT_MSG1);
    endif;

 SdFinishEx(szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2);
 
 ExFn_CreateUnInstall("delete");  
 
end;

  

在script.rul中的脚本:

                            #define DLG_ECSDBSETUPTYPE_DIALOG   "UserInfo" //自定义对话框名称
#define DLG_ECSDBSETUPTYPE_ID       0  //自定义对话框ID,设置为0
#define svTxApp "DingSi.Constructor.AppForm.exe.config"
#define RdSQL     1388 //RadioButton的资源ID
#define RdOther   1305 
#define TxAddr    1302  //text的资源ID
#define TxName    1392
#define TxPass    1394 
#define TxRePass  1396   
#define TxServerName 1390 
#define TxControlName 1364
#define BtnNext    1 
#define TTT  "InsertConfigureFile.exe" 
#define FILE_SPEC "System.Transactions.resources.dll"

#define SEARCH_DIR "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\zh-CHS"
#define TITLE_TEXT "FindFile Example"  

prototype ExFn_CreateUnInstall(string);//参数是:create:创建,delete:删除  
//删除目录和快捷方式
export prototype ExFn_DeleteFolderIcon(string,string);
prototype DialogShowSdAskDestPath_ERP(); 
prototype BOOL InsrtInstallCrysalRpeort();  


NUMBER nDlgDBTypeSetup;
STRING svTxSQL,svTxAddr,svTxServerName,svTxName,svTxPass,svTxRePass,svTxControlName;
STRING rsvTxSQL,rsvTxAddr,rsvTxServerName,rsvTxName,rsvTxPass,rsvTxRePass,rsvTxControlName,rsFull;


prototype BOOL InsrtDotNetFramework();

function BOOL InsrtDotNetFramework()
 STRING svResult,szProg,szCmdLine ;
begin


if (FindFile (SEARCH_DIR, FILE_SPEC, svResult) < 0) then      

   //SdShowMsg("正在准备安装中文语言包,请稍候...",TRUE);
  // Delay(15);
           szProg=SUPPORTDIR^"langpack.exe";
           szCmdLine= "/q:a /c:\"install /q\"";
           if (LaunchAppAndWait(szProg,szCmdLine, NOWAIT)<0) then
           MessageBox("["+szProg+""+szCmdLine+"].",SEVERE);
           endif;                     
  
 return TRUE; 
else
  return TRUE;
endif;

end;        

 prototype  DialogShowSdLicense();

function DialogShowSdLicense()
    NUMBER  nResult;
    STRING  szTitle, szMsg;
    STRING  szLicenseFile, szQuestion;
begin

    szLicenseFile = SUPPORTDIR ^ "版权申明.txt";
    szTitle    = "";
    szMsg      = "";
    szQuestion = "";
    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );

    return nResult;
  
end;             
 
                        
             
             
             

               
///////////////////////////////////////////////////////////////////////
////创建卸载快捷方式
/////////////////////////////////////////////////////////////////////                
function ExFn_CreateUnInstall(flag)
string szfilename,szFolder ,strProductFolder,szmsg1,szmsg2;
number nresult;
 int  nPos;
begin    


 if flag = "create" then
  //   Add   uninstall   icon  
  szfilename  =   UNINSTALL_STRING +" /UNINSTALL";   
    nresult    =   StrFind(szfilename,".exe");  
    if  nresult >=0 then  
     StrSub(szmsg1,szfilename,0,nresult   +   4);  
     StrSub(szmsg2,szfilename,nresult   +   4,200);  
     szfilename   =   "\""   +   szmsg1   +   "\""   +szmsg2;   
    endif;
    //AddFolderIcon(szFolder,"卸载 "+@PRODUCT_NAME,szfilename,WINDIR,"",0,"",REPLACE);

   nPos = StrFind("建设工程项目施工集成管理系统", "|") + 1;
 StrSub(strProductFolder, "建设工程项目施工集成管理系统", nPos, -1);  
  AddFolderIcon(FOLDER_PROGRAMS ^ strProductFolder, "卸载",szfilename, "","",0, "", NULL ); 
 else
 
   //删除快捷方式
  szFolder   =   FOLDER_PROGRAMS+"\\建设工程项目施工集成管理系统"; 
  szfilename   =   UNINSTALL_STRING +" /UNINSTALL";  
    nresult   =   StrFind(szfilename,".exe"); 
    if  nresult >=0 then 
     StrSub(szmsg1,szfilename,0,nresult + 4); 
     StrSub(szmsg2,szfilename,nresult+ 4,200); 
     szfilename   =   "\""   + szmsg1 +   "\""   +szmsg2;  
    endif;
  ExFn_DeleteFolderIcon(szFolder,szfilename); 
 endif;
end;


//删除目录和快捷方式
function ExFn_DeleteFolderIcon(FOLDER,ICON)
begin
    // Display the folder.
    //ShowProgramFolder (FOLDER, SW_SHOW);
    //Delay (3);
    // Delete the 'Notepad Example' icon.
  //  if (DeleteFolderIcon (FOLDER, ICON) < 0) then
  //      MessageBox ("删除快捷方式失败.ICON:"+ICON, SEVERE);
  //  endif;
    // Delete the 'Example folder' icon.
    if (DeleteProgramFolder (FOLDER) < 0) then
     //删除第一个快捷方式的时候这个目录删除是失败的,但第二个快捷方式被删除的时候就不会失败了
        //MessageBox ("删除目录失败.FOLDER:"+FOLDER, SEVERE);
    endif;
end;
        


function BOOL InsrtInstallCrysalRpeort()
 STRING svResult,szProg,szCmdLine ;
begin


 if (SYSINFO.WINNT.bWinXP ) then     
       return TRUE; 
      elseif (SYSINFO.WINNT.bWin2000 ) then     
        return TRUE;
      elseif ( SYSINFO.WINNT.bWinServer2003) then     
        return TRUE;
       else
       szProg=SUPPORTDIR^"vcredist_x86.exe";
     //szCmdLine= "  /q:a /c:\"msiexec /i vcredist.msi /qn /l*v %temp%\vcredist_x86.log\" ";      
       szCmdLine= "  /q ";  
       if (LaunchAppAndWait(szProg,szCmdLine, NOWAIT)<0) then
       MessageBox("["+szProg+""+szCmdLine+"].",SEVERE);
       endif;      
     return TRUE; 
endif;
end;          

prototype BOOL CreatFont();

function BOOL CreatFont()
 STRING svResult,szProg,szCmdLine ;
begin

    szProg=SUPPORTDIR^"InstallFont.exe";
    szCmdLine= "";
    if (LaunchAppAndWait(szProg,szCmdLine, NOWAIT)<0) then
    MessageBox("["+szProg+""+szCmdLine+"].",SEVERE);
    endif;                     
 return TRUE; 

end;        


 

原文地址:https://www.cnblogs.com/lbg280/p/1298725.html