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

泄露秘密 提交于 2019-12-01 09:04:51

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.

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