Execute a command after uninstall

2019-06-22 07:35发布

问题:

I need my uninstall to run a command after it's removed the files it has installed. [UninstallRun] is no use as I understand it runs BEFORE files are removed. I kind of need a "postuninstall" flag.

Any suggestions as to how I can accomplish the above?

回答1:

See "Uninstall Event Functions" in the documentation. You can use for instance CurUninstallStepChanged when 'CurUninstallStep' is 'usPostUninstall'.



回答2:

In the same way there is a [Run] section, Inno allows to you to define an [UninstallRun] section to specify which files of your Installer package should be executed on unistall.

For example:

[UninstallRun]
Filename: {app}\Scripts\DeleteWindowsService.bat; Flags: runhidden;

Alternatively, solution proposed by @Sertac Akyuz, which makes use of event functions can be used for tunning a bit more unistalling actions. Here is an example of the usage of CurUninstallStepChanged function among other related functions.

https://github.com/HeliumProject/InnoSetup/blob/master/Examples/UninstallCodeExample1.iss

; -- UninstallCodeExample1.iss --
;
; This script shows various things you can achieve using a [Code] section for Uninstall

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme

[Code]
function InitializeUninstall(): Boolean;
begin
  Result := MsgBox('InitializeUninstall:' #13#13 'Uninstall is initializing. Do you really want to start Uninstall?', mbConfirmation, MB_YESNO) = idYes;
  if Result = False then
    MsgBox('InitializeUninstall:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;

procedure DeinitializeUninstall();
begin
  MsgBox('DeinitializeUninstall:' #13#13 'Bye bye!', mbInformation, MB_OK);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  case CurUninstallStep of
    usUninstall:
      begin
        MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall is about to start.', mbInformation, MB_OK)
        // ...insert code to perform pre-uninstall tasks here...
      end;
    usPostUninstall:
      begin
        MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);
        // ...insert code to perform post-uninstall tasks here...
      end;
  end;
end;


标签: inno-setup