首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在依赖项安装失败时中止安装

在依赖项安装失败时中止安装
EN

Stack Overflow用户
提问于 2016-05-10 07:12:12
回答 1查看 907关注 0票数 0

我有一个.msi文件和两个先决条件文件。按照我的代码,安装程序成功安装后将从.msi文件执行主exe文件。但是,如果.msi文件的前一个版本已经安装,那么它附带了修复和删除的选项。我的Run部分在卸载.msi文件后运行,我希望在应用程序删除msi文件后退出它,否则它将不会执行Run部分。有人能给我一些解决办法吗?

以下是我的Run部分:

代码语言:javascript
复制
[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代码:

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-10 08:39:41

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

代码语言:javascript
复制
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]条目,则使用 parameter

代码语言:javascript
复制
[Run]
Filename: "{app}\{#MyAppExeName}"; Parameters: "..."; Flags: nowait postinstall; \
    Description: "..."; Check: FileExists(ExpandConstant('{app}\{#MyAppExeName}'))

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37131619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档