How to execute a batch file on uninstall in Inno Setup?

隐身守侯 提交于 2020-01-11 06:31:04

问题


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

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; 

回答1:


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;

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.


Note that in general, you should not use batch files. You better script everything in Pascal code. That way you get much more robust code and error handling.



来源:https://stackoverflow.com/questions/44446223/how-to-execute-a-batch-file-on-uninstall-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!