inno-setup - Inno Setup 和 VC Redistributable 并优雅地处理退出代码 3010
问题描述
在我的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 退出代码的官方文档,但它似乎是软重启。无论如何,今天他们尝试了我的安装程序并且它工作了(因为他们昨晚切换了他们的 PC):
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 安装中处理这种情况?
解决方案
如果我理解正确,退出代码意味着安装程序需要重新启动机器。
在这种情况下,当退出代码为 3010 时,您可以实现NeedRestart
事件函数来请求重启。
添加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;
推荐阅读
- javascript - 如何通过过渡打开/关闭文本?
- java - 如何使用各自的模式验证整个 json 以便在 java 中集成
- java - 如何在 jboss 中修复“IJ000305:发生连接错误”
- python - 为什么我不断收到“无法找到元素”
- reactjs - 是节点 5.0.3 的反应构建
- flutter - 为什么发布应用程序不能作为调试应用程序工作?
- python - 为什么我不能在 Python 3 中反转所有迭代器?
- postgresql - 如何使用变量通过 pgx 驱动程序获取不同的表?
- java - 从 Spring Boot 中以 PDF 内容类型生成内容的外部 Rest API 提取响应字节的正确方法是什么?
- php - 尝试登录 wordpress 管理面板时突然开始收到警报