[英]Inno Setup and VC Redistributable and handling exit code 3010 gracefully
在我的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
事件函數來請求重新啟動,當退出代碼為 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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.