Abort installation when dependency fails to install

女生的网名这么多〃 提交于 2019-12-13 12:47:03

问题


I have one .msi file and two prerequisites files. As per my code, the setup will execute main exe file from .msi file after successful installation. But if the previous version of .msi file is already installed, it coming with the option of Repair and Remove. My Run section is running after I uninstalled .msi file and I want to quit the application after it removed msi file or it will not execute the Run section. Can anyone please suggest me some solutions?

Here is my Run section:

[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..."

Here is my Pascal code:

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:


You probably want to abort the installation when the dependency fails to install:

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;

If you want the installation to continue, but you just need to skip the [Run] entry, use the Check parameter:

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

Btw, the StatusMsg parameter is not used with postinstall entries. And I'm still not sure if the installer-like Parameters are relevant for this program.



来源:https://stackoverflow.com/questions/37131619/abort-installation-when-dependency-fails-to-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!