gpt4 book ai didi

installation - Inno Setup:如何在安装过程中中止/终止安装?

转载 作者:行者123 更新时间:2023-12-03 13:16:44 26 4
gpt4 key购买 nike

在安装过程中,我运行了一个bat文件。如果bat文件返回错误,则需要中止/终止安装程序。我希望它做一个MsgBox告诉用户发生了什么,然后让中止显示并像用户按下“取消”按钮一样操作。

是否可以中止/终止设置?

代码示例将不胜感激。

[Run]
Filename: {tmp}\test.bat; WorkingDir: {tmp}; Flags: waituntilterminated runhidden

最佳答案

问题是在成功完成安装过程后会出现[Run]
因此,您目前不能取消,只能卸载。
另外,[Run]不允许您获取退出代码。

因此,您有一些选择。

使用事件:procedure CurStepChanged(CurStep: TSetupStep);
并且使用{tmp}\test.batExec调用ExecAsOriginalUser都返回ResultCode。然后,您可以提示用户卸载。

但是我认为执行取消会更容易。

为此,请在项目中的最后一个文件上创建一个AfterInstall事件。
并从该事件中执行程序,因为您可以从该事件中取消。

这是一些示例代码,显示了如何实现。

[Files]
Source: "MYPROG.EXE"; DestDir: "{app}"; AfterInstall: MyAfterInstall

[Code]
procedure MyAfterInstall();
var
ResCode : Integer;
begin
if Exec(ExpandConstant('{tmp}') + '\test.bat',
'', SW_HIDE, ewWaitUntilTerminated, ResCode) then
begin
{ Program Ran successfully ResCode now contains exit code results }

{ if Exit was 10 then Cancel Installation. }
if ResCode = 10 then
begin
WizardForm.Close;
end;
end
else
begin
{ Problem running Program }
MsgBox('Error', SysErrorMessage(ResCode), mbError, MB_OK);
end;

end;

关于installation - Inno Setup:如何在安装过程中中止/终止安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6345920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com