在Inno Setup中,是否可以将条件语句添加到[Run]部分的执行中?

时间:2008-12-11 16:47:59

标签: inno-setup

或者可以手动更新内置进度条吗? 基本上我有2个MSI并使用Inno Setup作为引导程序,根据用户输入,将安装一个或两个MSI。我在CurStepChanged中使用Exec语句有一些工作,但它不会更新进度条,因为文件被解压缩,看起来安装程序已经停止。我想最终的结果是我想要一些进度条更新,同时将文件解压缩到临时文件夹。以下是我目前的代码:

procedure CurStepChanged(CurStep: TSetupStep);
var
    ResultCode: Integer;
begin
    if(CurStep = ssInstall) then begin
        if(InstallServer) then begin
            ExtractTemporaryFile('ServerSetup.msi');
            Exec('msiexec',ExpandConstant('/i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
        end;
        if(InstallClient) then begin
            ExtractTemporaryFile('ClientSetup.msi');
            Exec('msiexec',ExpandConstant('/i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
        end;
    end;
end;

1 个答案:

答案 0 :(得分:24)

为什么不尝试这样的事情:

[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Client
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Server

[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Components: Client
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Components: Server

[Components]
Name: Client; Description: Client Installation
Name: Server; Description: Server Installation

当然,您不一定要使用Components。您没有写下如何决定运行哪个安装程序。如果您需要更复杂的逻辑,您还可以使用Check functions,如下所示:

[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckClient
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckServer

[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Check: CheckClient
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Check: CheckServer

[Code]
function CheckClient: Boolean;
begin
  Result := WhateverCondition;
end;

function CheckServer: Boolean;
begin
  Result := WhateverOtherCondition;
end;