inno-setup - Inno Setup 和 VC Redistributable 并优雅地处理退出代码 3010

标签 inno-setup pascalscript vcredist

在我的 CurStepChanged 过程中,我有一些安装 Visual Studio Redistributable 的代码(如果需要)。代码片段:

if (bVcRedist64BitNeeded) then
begin
    if Exec(ExpandConstant(vcRedist64BitPath), '/install /passive /norestart', '',
            SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
        { handle success if necessary; ResultCode contains the exit code }
        Log('VS Redist (64 bit) installer exit code = ' + IntToStr(ResultCode));
        if not (ResultCode = 0) then begin
            MsgBox(ExpandConstant('{cm:InstallFailed,Visual Studio x64 Redistributable}'), mbInformation, MB_OK);
            Abort();
        end;
    end
    else begin
        { The execution failed for some reason }
        Log('VS Redist (64 bit) installer exit code = ' + IntToStr(ResultCode));
        MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
        Abort();
    end;
end;

我有一位用户说我的软件安装程序失败,所以我要求他们向我发送他们的日志。在所有日志的末尾,它与此类似:

2020-09-05 14:37:48.034   VS Redist (64 bit) installer exit code = 3010
2020-09-05 14:37:48.035   Message box (OK):
                          The installation of Visual Studio x64 Redistributable failed. The Meeting Schedule Assistant installation will be aborted.
2020-09-05 14:38:38.352   User chose OK.
2020-09-05 14:38:38.352   CurStepChanged raised an exception.
2020-09-05 14:38:38.353   Need to restart Windows? No
2020-09-05 14:38:38.373   Exception message:
2020-09-05 14:38:38.374   Message box (OK):
                          Internal error: Expression error 'Runtime error (at 191:1960):
                          
                          Exception: Operation aborted.'
2020-09-05 14:38:40.747   User chose OK.
2020-09-05 14:38:40.747   Exception message:
2020-09-05 14:38:40.747   Message box (OK):
                          Internal error: Expression error 'Runtime error (at 191:1960):
                          
                          Exception: Operation aborted.'
2020-09-05 14:38:42.082   User chose OK.
2020-09-05 14:38:42.103   Exception message:
2020-09-05 14:38:42.104   Message box (OK):
                          Out Of Range.
2020-09-05 14:38:44.052   User chose OK.
2020-09-05 14:38:51.259   -- Run entry --
2020-09-05 14:38:51.259   Run as: Original user
2020-09-05 14:38:51.259   Type: Exec
2020-09-05 14:38:51.260   Filename: C:\Program Files (x86)\Meeting Schedule Assistant\MeetSchedAssist.exe

我注意到 redist 设置正在退出,结果为 3010。我找不到任何有关 redist 退出代码的官方文档,但它似乎是软重启。不管怎样,今天他们尝试了我的安装程序,它成功了(因为他们昨晚更换了电脑):

2020-09-06 13:08:38.707   VS Redist (64 bit) installer exit code = 0
2020-09-06 13:09:33.070   VS Redist (32 bit) installer exit code = 0
2020-09-06 13:09:33.071   Need to restart Windows? No
2020-09-06 13:10:07.741   -- Run entry --
2020-09-06 13:10:07.741   Run as: Original user
2020-09-06 13:10:07.741   Type: Exec
2020-09-06 13:10:07.741   Filename: C:\Program Files (x86)\Meeting Schedule Assistant\MeetSchedAssist.exe

所以我假设 3010 确实意味着软重启?如果是这样,我们在 Inno Setup 安装中是否有更好的方法来处理这种情况?

最佳答案

如果我理解正确的话,退出代码意味着安装程序需要重新启动计算机。

在这种情况下,您可以实现 NeedRestart event function当退出代码为 3010 时请求重新启动。

添加NeedRestart事件函数和NeedsRestart全局变量:

var
  NeedsRestart: Boolean;

function NeedRestart(): Boolean;
begin
  Result := NeedsRestart;
end;

并将退出代码测试逻辑修改为:

if ResultCode = 3010 then
begin
  Log('Need restart');
  NeedsRestart := True;
end
  else
if ResultCode <> 0 then
begin
  MsgBox(
    ExpandConstant('{cm:InstallFailed,Visual Studio x64 Redistributable}'),
    mbInformation, MB_OK);
  Abort();
end;

类似问题:How to restart Inno Setup installer based on result of procedure that executes a program/subinstaller

关于inno-setup - Inno Setup 和 VC Redistributable 并优雅地处理退出代码 3010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63767288/

相关文章:

inno-setup - 如何在单个 Inno Setup 安装程序中添加 x86 和 x64 VC++ 2019 Redistributables?

installation - Inno-setup:基于现有页面类型的自定义向导页面

WIX 在安装时运行 vcredist_x64.exe

inno-setup - Inno Setup 页面列表,按参数和屏幕截图顺序排列

registry - 将值写入 Inno Setup 中存储在数组中的所有注册表项

inno-setup - 如何检查注册表项是否存在并退出安装程序

visual-c++ - 如何处理 Visual Studio 2017 的 Microsoft Visual C++ Redistributable?

msdn - 哪里可以下载vcredist?

delphi - 无法定义记录指针

inno-setup - 如何使用Inno Setup添加计划任务