问题
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