当Run命令失败时,如何强制Inno Setup设置失败?

DSO*_*DSO 10 inno-setup

我在[Run]Inno Setup脚本部分有一些命令.现在,如果它们中的任何一个返回失败代码(非零返回值),则设置继续而不向用户发出任何警告.所需的行为是让安装失败并回滚.

我如何启用此功能?我找不到任何Run会强制此行为的条目标志.我错过了什么吗?

GSe*_*erg 9

就我而言,您必须使用[Code]部分,使用Exec函数运行文件,检查ResultCode返回并运行卸载脚本.


Iva*_*gin 5

我这样做是这样的:

  1. {tmp}\install.error使用Inno Setup的过程BeforeInstall参数将错误消息(中止确认消息或通知消息)写入临时文件SaveStringToUTF8File。您可以使用Inno Setup的常量,例如{cm:YourCustomMessage}

  2. 使用Windows命令外壳cmd.exe /s /c运行所需的程序。还可以使用条件执行del与命令&&- https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx。因此,如果命令成功(退出代码0),则将删除错误消息文件。请注意中的特殊报价处理cmd.exe /s /c。使用下面的代码作为示例。

  3. 检查错误信息文件是否存在{tmp}\install.error使用Inno Setup的的AfterInstall参数与任一ConfirmInstallAbortOnErrorNotifyInstallAbortOnError程序取决于错误的严重性。他们将通过适当的通知或确认(以及可选的日志文件显示)中止安装,并使用以下命令执行回滚Exec(ExpandConstant('{uninstallexe}'), ...

  4. ShouldAbortInstallation全局变量用于保持状态。Inno Setup的ShouldSkipPage(PageID: Integer)功能用于隐藏最后一页。本[Run]节中的所有命令都应使用Check带有CheckInstallationIsNotAborted功能的参数。这将防止它们在失败后执行。

请参见下面的示例。希望这可以帮助。

[CustomMessages]
InstallAbortOnErrorConfirmationMessage=An error has occurred during setup.%nAbort installation?
InstallAbortOnErrorNotificationMessage=An error has occurred during setup.%nInstallation will be aborted.
RunProgram1ErrorMsg=Post installation phase 1 failed. Should abort install?
RunProgram2ErrorMsg=Post installation phase 2 failed. Installation will be aborted. Please, contact tech support.
RunProgram1StatusMsg=Post installation phase 1 is in progress
RunProgram2StatusMsg=Post installation phase 2 is in progress

[Run]
; Write error text to file. Delete file on succeed. Abort installation if file exists after command execution.
Filename: "cmd.exe"; Parameters: "/s /c "" ""{app}\program1.exe"" /param1 /param2:""val2"" && del /F /Q ""{tmp}\install.error"" """; \
  WorkingDir:"{app}"; Flags: runhidden; \
  BeforeInstall: SaveStringToUTF8File('{tmp}\install.error', '{cm:RunProgram1ErrorMsg}', False); \
  AfterInstall: ConfirmInstallAbortOnError('{tmp}\install.error', '{app}\logs\setup.log'); \
  StatusMsg: "{cm:RunProgram1StatusMsg}"; \
  Check: CheckInstallationIsNotAborted;
Filename: "cmd.exe"; Parameters: "/s /c "" ""{app}\program2.exe"" && del /F /Q ""{tmp}\install.error"" """; \
  WorkingDir:"{app}"; Flags: runhidden; \
  BeforeInstall: SaveStringToUTF8File('{tmp}\install.error', '{cm:RunProgram2ErrorMsg}', False); \
  AfterInstall: NotifyInstallAbortOnError('{tmp}\install.error', '{app}\logs\setup.log'); \
  StatusMsg: "{cm:RunProgram2StatusMsg}"; \
  Check: CheckInstallationIsNotAborted;
Run Code Online (Sandbox Code Playgroud)
[CustomMessages]
InstallAbortOnErrorConfirmationMessage=An error has occurred during setup.%nAbort installation?
InstallAbortOnErrorNotificationMessage=An error has occurred during setup.%nInstallation will be aborted.
RunProgram1ErrorMsg=Post installation phase 1 failed. Should abort install?
RunProgram2ErrorMsg=Post installation phase 2 failed. Installation will be aborted. Please, contact tech support.
RunProgram1StatusMsg=Post installation phase 1 is in progress
RunProgram2StatusMsg=Post installation phase 2 is in progress

[Run]
; Write error text to file. Delete file on succeed. Abort installation if file exists after command execution.
Filename: "cmd.exe"; Parameters: "/s /c "" ""{app}\program1.exe"" /param1 /param2:""val2"" && del /F /Q ""{tmp}\install.error"" """; \
  WorkingDir:"{app}"; Flags: runhidden; \
  BeforeInstall: SaveStringToUTF8File('{tmp}\install.error', '{cm:RunProgram1ErrorMsg}', False); \
  AfterInstall: ConfirmInstallAbortOnError('{tmp}\install.error', '{app}\logs\setup.log'); \
  StatusMsg: "{cm:RunProgram1StatusMsg}"; \
  Check: CheckInstallationIsNotAborted;
Filename: "cmd.exe"; Parameters: "/s /c "" ""{app}\program2.exe"" && del /F /Q ""{tmp}\install.error"" """; \
  WorkingDir:"{app}"; Flags: runhidden; \
  BeforeInstall: SaveStringToUTF8File('{tmp}\install.error', '{cm:RunProgram2ErrorMsg}', False); \
  AfterInstall: NotifyInstallAbortOnError('{tmp}\install.error', '{app}\logs\setup.log'); \
  StatusMsg: "{cm:RunProgram2StatusMsg}"; \
  Check: CheckInstallationIsNotAborted;
Run Code Online (Sandbox Code Playgroud)