如何在Inno Setup中卸载时执行批处理文件? [英] How to execute a batch file on uninstall in Inno Setup?

查看:795
本文介绍了如何在Inno Setup中卸载时执行批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

I'm using code from How do you execute command line tools without using batch file in Inno Setup response to execute all my batch files on installation (before, after).

否,我只想在用户单击是"以卸载程序时执行它们,但是找不到解决方法.它在确认之前执行

No I want to execute them just when user click "YES" to uninstaller, but can't find a way to do it. It executes before the confirmation

这是我来自[Code]部分的代码:

Here is my code from [Code] section:

function InitializeUninstall(): Boolean;
var
  ResultCode : Integer;    
begin
  Result := True;
  Exec(ExpandConstant('{app}\scripts\unset.bat'), '', '',
       SW_HIDE, ewWaitUntilTerminated, ResultCode); 
end; 

推荐答案

将您的代码移至 CurUninstallStepChanged(usUninstall) .确认卸载后 会触发该事件.

Move your code to the CurUninstallStepChanged(usUninstall). That event is triggered after the confirmation of uninstallation.

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  ResultCode : Integer;    
begin
  if CurUninstallStep = usUninstall then
  begin
    Exec(ExpandConstant('{app}\scripts\unset.bat'), '', '',
         SW_HIDE, ewWaitUntilTerminated, ResultCode); 
  end;
end;


尽管使用 [UninstallRun]部分更容易.


Though it's easier to use [UninstallRun] section.

[UninstallRun]
Filename: "{app}\scripts\unset.bat"; Flags: runhidden

在确认之后,但在卸载任何文件之前,也会处理该部分.请参阅卸载顺序.

The section is also processed after the confirmation, but before any files are uninstalled. See Uninstallation order.

请注意,通常不应使用批处理文件.您最好用Pascal代码编写所有脚本.这样,您将获得更健壮的代码和错误处理.

这篇关于如何在Inno Setup中卸载时执行批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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