当依赖项安装失败时中止安装

Abort installation when dependency fails to install

我有一个 .msi 文件和两个先决条件文件。根据我的代码,安装程序将在成功安装后从 .msi 文件执行主 exe 文件。但如果之前版本的 .msi 文件已经安装,它会附带修复和删除选项。在我卸载 .msi 文件后,我的 Run 部分是 运行,我想在删除 msi 文件后退出应用程序,否则它不会执行 Run 部分。谁能给我一些解决方案建议?

这是我的 Run 部分:

[Run]
Filename: "{app}\{#MyAppExeName}"; \
    Parameters: "/verysilent /group=""{groupname}\Macrowire 2.5 Pro"" /mergetasks=""desktopicon,file_association"""; \
    Flags: nowait postinstall; \
    Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \
    StatusMsg: "Installing Macrowire 2.5 Pro..."

这是我的 Pascal 代码:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var 
  ResultCode: integer;
begin
  ...
  if IsComponentSelected('Macrowire') or IsComponentSelected('Full') then
  begin
    ShellExec('', ExpandConstant('{app}\MacroWire 2.5 Pro.msi'), '', '', SW_SHOW,
      ewWaitUntilTerminated, ResultCode) 
  end;
  ...
end;

您可能想在依赖项安装失败时中止安装:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var 
  ResultCode: integer;
begin
  ...
  if IsComponentSelected('Macrowire') or IsComponentSelected('Full') then
  begin
    { Using Exec, the ShellExec is an overkill }
    Exec(ExpandConstant('{app}\MacroWire 2.5 Pro.msi'), '', '', SW_SHOW,
         ewWaitUntilTerminated, ResultCode);
    // Here we are testing the existence of the installed binary.
    // A more generic solution would be to test result code of the installer:
    // if ResultCode <> 0 then
    if not FileExists(ExpandConstant('{app}\{#MyAppExeName}')) then
    begin
      Result := 'Failed to install MacroWire';
      Exit;
    end;
  end;
  ...
end;

如果您希望安装继续,但您只需要跳过 [Run] 条目,请使用 Check parameter:

[Run]
Filename: "{app}\{#MyAppExeName}"; Parameters: "..."; Flags: nowait postinstall; \
    Description: "..."; Check: FileExists(ExpandConstant('{app}\{#MyAppExeName}'))

顺便说一句,StatusMsg 参数不与 postinstall 条目一起使用。而且我仍然不确定类似安装程序的 Parameters 是否与该程序相关。