【问题标题】:Inno Setup: Install other installer and run it before continuing my installInno Setup:安装其他安装程序并在继续安装之前运行它
【发布时间】:2013-11-04 12:58:04
【问题描述】:

到目前为止,这是我的代码的 [Files] 部分:

[Files]
Source: "other_installer.exe"; DestDir: "{app}"
Source: "myprogram.exe"; DestDir: "{app}"
Source: "data.dat"; DestDir: "{app}"
Source: "otherdata.dat"; DestDir: "{app}"

我的程序依赖于另一个程序来运行。我已经在我的安装程序中包含了这个程序的安装程序(“other_installer.exe”)。我想做的是在复制完成后立即启动此安装程序,然后继续执行“myprogram.exe”和其他操作。

我在 Inno 设置帮助中搜索并找到了 BeforeInstall 的文档,但他们没有运行另一个应用程序的示例。我相信它应该是这样的:

[Files]
Source: "other_installer.exe"; DestDir: "{app}"
Source: "myprogram.exe"; DestDir: "{app}"; BeforeInstall: // RUN OTHER_INSTALLER.EXE //
Source: "data.dat"; DestDir: "{app}"
Source: "otherdata.dat"; DestDir: "{app}"

【问题讨论】:

    标签: installation inno-setup


    【解决方案1】:

    AfterInstall 参数可能更适合您的方式。以下脚本将在处理完OtherInstaller.exe 文件条目后立即执行RunOtherInstaller 函数。它在那里尝试执行刚刚安装的OtherInstaller.exe 文件,如果失败,它会向用户报告一条错误消息。请注意,您不能从该功能中断安装,因此以这种方式执行您想要的操作并不安全:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    [Files]
    Source: "OtherInstaller.exe"; DestDir: "{app}"; AfterInstall: RunOtherInstaller
    Source: "OtherFile.dll"; DestDir: "{app}"
    
    [Code]
    procedure RunOtherInstaller;
    var
      ResultCode: Integer;
    begin
      if not Exec(ExpandConstant('{app}\OtherInstaller.exe'), '', '', SW_SHOWNORMAL,
        ewWaitUntilTerminated, ResultCode)
      then
        MsgBox('Other installer failed to run!' + #13#10 +
          SysErrorMessage(ResultCode), mbError, MB_OK);
    end;
    

    【讨论】:

    • 是否可以存储错误并在以后中断(并可能回滚)安装?
    • 我试过了,虽然我得到了错误:“请求需要提升”。请问如何管理?
    • 它就像一个魅力。但是,对于不可执行的文件怎么办?我正在尝试打开一个 p12 证书文件,但它向我抛出了错误:%1 is not a valid win32 application
    【解决方案2】:

    另一个运行必备安装程序的好时机是在PrepareToInstall 事件函数中。 (基本结构见 Inno 提供的示例脚本,实际执行见 TLama 的代码。)

    PrepareToInstall 的主要优点是它允许您处理来自子安装程序的错误和重新启动请求 - 使用 AfterInstall 不会。

    它的主要缺点是您必须手动 ExtractTemporaryFile 运行子安装所需的任何东西,因为这发生在文件被提取之前。

    【讨论】:

      【解决方案3】:

      您可以使用 AfterInstall,请在帮助中查找。 刚刚复制文件时,我将启动您设置为“AfterInstall:”的功能/程序。

      在这个函数/过程中,使用 Exec 并启动另一个安装程序。

      【讨论】:

      • 是的,如果我的回答与你的相似,我很抱歉
      猜你喜欢
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多