一个installsheild脚本安装的代码

//===========================================================================
//
//  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); */
#define szKey "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Infomedia_Dog\\"
STRING oldGuid;
BOOL OS64,OS32;
//获取安装包位置
STRING SETUPEXEDIR[MAX_PATH + 1];
string setupDIR;
number  nBuffer; 

export prototype UninstallOldVersion(); //卸载旧版本
export prototype WriteInstallGuid();//将本安装包的GUID写入注册表

//prototype YiJiaoReg(STRING); //声明函数
//---------------------------------------------------------------------------
// 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 szFeatureName;
STRING serviceTarget;
STRING szDocFile;

begin     

 

szFeatureName="Client";

serviceTarget=TARGETDIR^"AutoUpdater.exe";

if(FindFile(TARGETDIR, "AutoUpdater.exe", szDocFile)=0) then

if (LaunchApp (serviceTarget, "") < 0) then

MessageBox ("Unable to launch "+serviceTarget+".", SEVERE);

endif;

endif;
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, szOpt1, szOpt2;
    NUMBER bOpt1, bOpt2; 
    STRING szfilename,szFolder ,szmsg1,szmsg2;
    NUMBER nresult;
begin 


szfilename = UNINSTALL_STRING +" /UNINSTALL";

nresult = StrFind(szfilename,".exe");

if nresult >=0 then

StrSub(szmsg1,szfilename,0,nresult + 4);
//YiJiaoReg(szmsg1);//写注册表
WriteInstallGuid();//写注册表
StrSub(szmsg2,szfilename,nresult + 4,200);

LongPathToQuote(szmsg1, FALSE );

LongPathToQuote(szmsg2, FALSE );

szfilename = "\"" + szmsg1 + "\"" +szmsg2;

endif;

AddFolderIcon(FOLDER_PROGRAMS^"中国艺交所会员客户端","Uninstall",szfilename,WINDIR,"",0,"",REPLACE);

                  
 Disable(STATUSEX);

 bOpt1   = FALSE;
    bOpt2   = FALSE;
   
    if ( BATCH_INSTALL ) then
     SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
    else
     SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bOpt1 , bOpt2 );
 endif;
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, szOpt1, szOpt2;
    NUMBER bOpt1, bOpt2; 
    STRING szItemName;
    STRING szProgramFolder;
begin

 


// 删除开始所有程序中的AliProbe文件夹
  DeleteProgramFolder("中国艺交所会员客户端");
 
  // 删除桌面上的快捷方式
  szItemName = "中国艺交所会员客户端";
  szProgramFolder = FOLDER_DESKTOP;
  DeleteFolderIcon(szProgramFolder, szItemName);
 
  // 删除安装目录文件夹
  DeleteProgramFolder(TARGETDIR);
 Disable(STATUSEX);
   
    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;

 bOpt1   = FALSE;
    bOpt2   = FALSE;   

    if ( BATCH_INSTALL ) then
     SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
    else   
        SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bOpt1 , bOpt2 );
    endif;
end;
// SdWelcome ----------------------------------------------------------------
function  SdWelcome(szTitle, szMsg)
    string  szDlg, szTemp;
    number  nId, nMessage, nTemp, nSdDialog;
    HWND    hwndDlg;
    BOOL    bDone;
begin

    szDlg     = SD_DLG_WELCOME;
    nSdDialog = SD_NDLG_WELCOME;
   
   
     szTitle="中国艺交所会员客户端安装向导"; 
     szMsg="中国艺交所会员客户端安装程序正在准备安装向导,它将引导您完成剩余的过程,请稍后。";

    // record data produced by this dialog
    if(MODE=SILENTMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdWelcome );
        SilentReadData( szAppKey, "Result", DATA_NUMBER, szTemp, nId );
        return nId;
    endif;

    // ensure general initialization is complete
    if(!bSdInit) then
        SdInit();
    endif;

    if(EzDefineDialog( szDlg, "", "", SD_NDLG_WELCOME ) = DLG_ERR) then
        return -1;
    endif;

    Disable( BACKBUTTON );

    // Loop in dialog until the user selects a standard button
    bDone = FALSE;

    while (!bDone)

        nId = WaitOnDialog( szDlg );

        switch(nId)

        case DLG_INIT:

            // Put the corresponding Info in the List Field
            if( szMsg != "" ) then
                SdSetStatic(szDlg, SD_STA_MSG, szMsg);
            endif;

            hwndDlg = CmdGetHwndDlg( szDlg );
            SdGeneralInit( szDlg, hwndDlg, STYLE_NORMAL, szSdProduct );

            SdSetDlgTitle(szDlg, hwndDlg, szTitle);

        case NEXT:

            nId    = NEXT;
            bDone  = TRUE;

        case BACK:

            nId    = BACK;
            bDone  = TRUE;

        case DLG_ERR:

            SdError( -1, "SdWelcome" );
            nId    = -1;
            bDone  = TRUE;

        case DLG_CLOSE:

            SdCloseDlg( hwndDlg, nId, bDone );

        default:

            // check standard handling
            if(SdIsStdButton( nId ) && SdDoStdButton( nId )) then
                bDone = TRUE;
            endif;

        endswitch;

    endwhile;

    // Cleanup Dialog
    EndDialog( szDlg );
    ReleaseDialog( szDlg );
    SdUnInit();
    Enable( BACKBUTTON );

    // record data produced by this dialog
    if(MODE=RECORDMODE) then
        SdMakeName( szAppKey, szDlg, szTitle, nSdWelcome );
        SilentWriteData( szAppKey, "Result", DATA_NUMBER, "", nId );
    endif;

    return nId;

end;
//---------------------------------------------------------------------------
// 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;
 BOOL bCustom, bIgnore1, bIgnore2;  
 NUMBER nvType;
 STRING  szPath;  
 STRING ProductCode,VERCHEKER,szCMDLineTest;
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));       

    // Added in InstallShield 15 - Show an appropriate error message if
    // -removeonly is specified and the product is not installed.
   
     
     UninstallOldVersion();
    if( REMOVEONLY ) then
        Disable( DIALOGCACHE );
  szMsg = SdLoadString( IDS_IFX_ERROR_PRODUCT_NOT_INSTALLED_UNINST );
     SdSubstituteProductInfo( szMsg );
  MessageBox( szMsg, SEVERE );
  abort;
    endif;
   
 nSetupType = TYPICAL; 
    
     /*RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
    nvType = REGDB_NUMBER;
    if(RegDBKeyExist("SOFTWARE\\YiJiao")>0) then
      RegDBGetKeyValueEx("SOFTWARE\\YiJiao\\","uninstall",nvType,szPath,nvSize);
      if(Is (FILE_EXISTS, szPath)>0) then
      MessageBox ("检测到本机安装有其他版本,请按操作移除其它版本! ", INFORMATION);
      RegDBDeleteKey("SOFTWARE\\YiJiao");
      LaunchAppAndWait(szPath,"",WAIT);
      WaitForApplication(LAAW_PROCESS_INFORMATION.hProcess, LAAW_PROCESS_INFORMATION.dwProcessId, INFINITE, LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT);

      endif;
      RegDBDeleteKey("SOFTWARE\\YiJiao");
     endif;  */
    
Dlg_SdWelcome:
    szTitle = "";
    szMsg   = "";
    nResult = SdWelcome(szTitle, szMsg);
    if (nResult = BACK) goto Dlg_SdWelcome;
 
 szTitle   = "";
 svName    = "";
    svCompany = "";
   
Dlg_SdAskDestPath:     
    nResult = SdAskDestPath(szTitle, szMsg, INSTALLDIR, 0);
    if (nResult = BACK) goto Dlg_SdWelcome;

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_SdAskDestPath;   
     else
      goto Dlg_SdFeatureTree;
     endif;
    endif;

Dlg_SdStartCopy:
    szTitle = "";
    szMsg   = "";
    nResult = SdStartCopy2( szTitle, szMsg );   
 
    if (nResult = BACK) then
       goto Dlg_SQL;;
    endif;

    // Added in IS 2009 - Set appropriate StatusEx static text.
    SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) );

    // setup default status
    Enable(STATUSEX);
     
     //判断注册表中的值
    /*RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
    nvType = REGDB_NUMBER;
    if(RegDBKeyExist("SOFTWARE\\YiJiao")>0) then
           RegDBGetKeyValueEx("SOFTWARE\\YiJiao\\","ProductCode",nvType,szPath,nvSize);
           ProductCode="\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" +szPath;
     if(RegDBKeyExist(ProductCode)>0) then
       //RegDBGetKeyValueEx("\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F7BCAE73-5488-494D-B23F-C792D8C4A97D}","UninstallString",nvType,szPath,nvSize);
        RegDBDeleteKey(ProductCode); 
        endif; 
     // 删除开始所有程序中的AliProbe文件夹
    DeleteProgramFolder("中国艺交所会员客户端");
 
    // 删除桌面上的快捷方式
    DeleteFolderIcon(FOLDER_DESKTOP, "中国艺交所会员客户端");
    
    
    RegDBGetKeyValueEx("SOFTWARE\\YiJiao","install",nvType,szPath,nvSize);
   
    // 删除安装目录文件夹
    DeleteProgramFolder(szPath);  
    RegDBDeleteKey("SOFTWARE\\YiJiao");
    endif;  */  
   
    //YiJiaoReg(); 
    /*if(RegDBKeyExist("SOFTWARE\\YiJiao")>0) then
     
      RegDBGetKeyValueEx("SOFTWARE\\YiJiao\\","ProductCode",nvType,szPath,nvSize);
       ProductCode="\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" +szPath;
     
 
              if (RegDBKeyExist(ProductCode) = 1)then  // has the key
             RegDBGetKeyValueEx(ProductCode,"UninstallString",nvType,szPath,nvSize);
                 VERCHEKER = SUPPORTDIR ^ "setup.iss";
                 XCopyFile ( VERCHEKER, "C://Program Files//InstallShield Installation Information//"+"ProductCode", COMP_NORMAL );
                 szCMDLineTest = "/s /f1/"+"C://Program Files//InstallShield Installation Information//"+"ProductCode"+"//setup.iss/";
                 LaunchAppAndWait( szPath, szCMDLineTest, LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT);
                WaitForApplication(LAAW_PROCESS_INFORMATION.hProcess, LAAW_PROCESS_INFORMATION.dwProcessId, INFINITE, LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT);
            endif;
               // 删除开始所有程序中的AliProbe文件夹
   
    RegDBDeleteKey("SOFTWARE\\YiJiao");
        endif;  */
     
    return 0;
end;
//---------------------------------------------------------------------------
// OnBegin
//
// The OnBegin event is called directly by the framework after the setup
// initializes.
//---------------------------------------------------------------------------
function OnBegin()
string svCurrentDir;  
//NUMBER   nvType,nvSize;
STRING   szPath;
string szNumName,szNumValue; 
number nType,nSize;
begin
 // TO DO: you may change default non-UI setting, for example
 //
 // You may also perform your custom initialization steps, check requirements, etc.

//GetCurrentDir(svCurrentDir);
 //svCurrentDir =  svCurrentDir+"这里的dotnetfx20.exe可到官网上下载
  //判断操作系统
     if (SYSINFO.bIsWow64) then
          OS64=TRUE;
     else
          OS32=TRUE;
     endif;
    //旧的安装GUID
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    if(RegDBKeyExist(szKey)>0)then
        szNumName="Dog";
        nType=REGDB_STRING;
        RegDBGetKeyValueEx(szKey,szNumName,nType,szNumValue,nSize);
        oldGuid= szNumValue;
    endif;  
 
   
    
 svCurrentDir =  SUPPORTDIR^"
这里的dotnetfx20.exe可到官网上下载
 RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);  //设置默认的注册表键值根节点
 // 判断是否存在.net
 if (RegDBKeyExist ("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0") <0 &&RegDBKeyExist ("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4") < 0) then
 //当上面判断了没有安装.net这个软件时,则启动光盘里
 //dotnetfx.exe安装程序来安装。
     MessageBox ("检测到本机未安装.Net FrameWork 4.0,下一步将会先安装.Net FrameWork 4.0 ", INFORMATION); 
     if(LaunchAppAndWait (svCurrentDir ,"", LAAW_OPTION_WAIT)<0) then    
     MessageBox ("找不到安装程序或者安装出错,请自行下载.Net FrameWork 4.0,手动安装", INFORMATION);
     return 0;
     endif;       
 endif;

end;
 //
 //
///将安装路径写进注册表
/*function YiJiaoReg(Path)
number nRootKey,nType,nSize;
string szKey,szNumName,szNumValue,szClass;
begin    
 //修改注册表
 nRootKey = HKEY_LOCAL_MACHINE;
 RegDBSetDefaultRoot (nRootKey); //置根为nRootKey
 //注册子项
 szKey="SOFTWARE\\YiJiao\\";
 if RegDBKeyExist(szKey) < 0 then
    //不存在“SOFTWARE//NNLLTEST”,创建这个项
    Disable(LOGGING);
    RegDBCreateKeyEx(szKey,""); 
    Enable(LOGGING);
 endif;
 //初始化每个键的公共值
 nType=REGDB_STRING;
 nSize=-1;
 //注册安装路径
 szNumName="install";
 szNumValue=TARGETDIR;
    RegDBSetKeyValueEx(szKey,szNumName,nType,szNumValue,nSize);  
   
 szNumName="uninstall";
 //szNumValue=UNINSTALL_STRING +" /UNINSTALL";//
 szNumValue=Path;
    RegDBSetKeyValueEx(szKey,szNumName,nType,szNumValue,nSize);
   
   
 szNumName="ProductCode";
 szNumValue="";//记录上个版本的产品号
    RegDBSetKeyValueEx(szKey,szNumName,nType,szNumValue,nSize);
   
    //设置为未注册版本
    szNumName="soft";
 szNumValue="0";
 if RegDBKeyExist(szKey) < 0 then
    //如果不存在这个项,就注册,如果存在,就跳过
    RegDBSetKeyValueEx(szKey,szNumName,nType,szNumValue,nSize);
    RegDBCreateKeyEx (szKey, szClass);
 endif;
end;  */


 ///卸载旧版本
function UninstallOldVersion() 
string szPath,UninstallString;
string szNumName,szNumValue;
number nType,nSize;
begin      
szPath=WINDIR+"Installer\\"+oldGuid;

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
UninstallString="

\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\InstallShield_"+oldGuid;
nType=REGDB_STRING;
szNumName="UninstallString";
RegDBGetKeyValueEx(UninstallString,szNumName,nType,szNumValue,nSize); //获取卸载脚本
    if(RegDBKeyExist(UninstallString)>0) then  
        //if(AskYesNo("Install the software detects an earlier version, in order to ensure the software is installed correctly uninstall that version!",NO)=YES) then  
                SdShowMsg("正在卸载旧版本请稍等...",TRUE);
                Delay(1);
                LaunchAppAndWait(szNumValue," /S",LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT);                
                //DeleteDir("C:\\Program Files (x86)\\InstallShield Installation Information\\"+oldGuid,ALLCONTENTS);
                //刷新注册表
                LaunchAppAndWait ( "","cmd /c gpupdate /force /wait:0 ",LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT|LAAW_OPTION_HIDDEN);  
                SdShowMsg("", FALSE);
                   //SdShowMsg("Uninstall is complete",TRUE);
                Delay(2);
                SdShowMsg("", FALSE);
                LaunchAppAndWait( WINSYSDIR^"cmd.exe", "/c rd /s/q \""+szPath+"\"", LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_WAIT | LAAW_OPTION_HIDDEN);
        //else
            //abort;
        //endif;
    endif;   
end;
 
 
//写注册表
function WriteInstallGuid()
string svSubStr,productCode;
number nRootKey,nType;
begin
    
    if(OS32=TRUE) then
        StrSub(svSubStr,UNINSTALL_STRING,57,38); //获取guid 
    else
        StrSub(svSubStr,UNINSTALL_STRING,63,38);
    endif;
    productCode=svSubStr;
    nRootKey=HKEY_LOCAL_MACHINE;
    RegDBSetDefaultRoot(nRootKey);
    nType=REGDB_STRING;
    RegDBSetKeyValueEx(szKey,"Dog",nType,productCode,-1);   
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, nType,nBuffer;
    STRING szTitle, szMsg, svDir, svResult, szCaption; 
    string setupDIR;
begin
    Dlg_Start:
    if( !REMOVEONLY ) then
      /*if(AskYesNo("计算机上已经安装了该版本,是否卸载?",YES)=NO) then
         abort;
      else */
          ComponentRemoveAll();     
         SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );  
      //endif;
    else
         ComponentRemoveAll();
        SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );     
    endif; 
    // setup default status
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100);
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值