依赖无法安装时中止安装

时间:2016-05-10 07:12:12

标签: inno-setup pascalscript

我有一个.msi文件和两个先决条件文件。根据我的代码,安装成功后,安装程序将从.msi文件执行main 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;

1 个答案:

答案 0 :(得分:1)

您可能希望在依赖项无法安装时中止安装:

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);
    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是否与此程序相关。