Inno Setup:如何在安装过程中中止/终止安装? [英] Inno Setup: How to abort/terminate setup during install?

查看:606
本文介绍了Inno Setup:如何在安装过程中中止/终止安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装过程中,我运行了一个bat文件.如果bat文件返回错误,则需要中止/终止安装程序.我希望它执行MsgBox告诉用户发生了什么,然后让异常终止外观和行为类似于用户按下取消按钮.

During my install, I run a bat file. If the bat file returns an error, I need to abort/terminate the setup. I'd like for it to do a MsgBox telling the user what happened, then for the abort to look and act like the user pressed the Cancel button.

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

Is it possible to abort/terminate the setup?

代码示例将不胜感激.

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

推荐答案

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

The problem is that [Run] occurs after the Installation process successfully complete. So you can't cancel at this point, you can only uninstall. Also [Run] does not allow you to get the exit code.

所以您有一些选择.

使用事件:procedure CurStepChanged(CurStep: TSetupStep);

并使用ExecExecAsOriginalUser调用{tmp}\test.bat都返回ResultCode.然后,您可以提示用户卸载.

And the call the {tmp}\test.bat using Exec or ExecAsOriginalUser both of these return the ResultCode. You can then prompt the user to uninstall.

但是我认为执行取消操作会更容易.

However I think that performing a cancel would be easier.

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

To do that, create an AfterInstall Event on the last file in your project. And execute the program from this event, as you can cancel from this event.

下面是一些示例代码,展示了如何实现.

Here is some sample code that shows how it could be done.

[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;

这篇关于Inno Setup:如何在安装过程中中止/终止安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆