Kawaii-Hachii
Kawaii-Hachii

Reputation: 1061

Running an application at the end of the uninstall in InnoSetup, handling the user cancelling

During un-installation, user will be asked "Are you sure to uninstall ...".

Then the user will click either "Yes" or "No".

Is it possible to catch this on the script?

Because I need to execute an application at the end of uninstallation process.

If I execute the application during "InitializeUninstall()", that is not correct because the user could cancel the uninstallation later (the above dialog is displayed AFTER this function).

Same with "DeInitializeUninstall()", this function is still executed even the user cancel the uninstallation.

Basically, I need to execute the application when the user is really un-installing (agreed to uninstall). Because I need to catch the ExitCode of this application to set the UninstallNeedRestart() function.

Thanks.

Upvotes: 2

Views: 2635

Answers (3)

Deanna
Deanna

Reputation: 24263

You can do this in the CurUninstallStepChanged() event function when it is called with the usPostUninstall parameter.

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
    if CurUninstallStep = usPostUninstall then
    begin
        // Do your uninstall time code here
        Exec(ExpandConstant('{app}\CleanUp.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
    end;
end;

Upvotes: 1

Jack Culhane
Jack Culhane

Reputation: 781

Another way to achieve this is using the [Run] and / or [UninstallRun] sections to run an executable after install / before uninstall.

You can run a executable to do whatever clean up you need.

Compile a helper exe to do what you want, or add the function to your main executable when supplied a command line parameter.

[Run]
Filename: "{app}\CleanUp.exe"; WorkingDir: "{app}"

[UninstallRun]
Filename: "{app}\CleanUp.exe"; Parameters: "/uninstall"; WorkingDir: "{app}"; RunOnceId: "CleanUpApp"

More information in the inno setup documentation: http://www.jrsoftware.org/ishelp/index.php?topic=runsection

You need to add the helper exe to the installation too:

[Files]
...
Source: "C:\myprog\CleanUp.exe"; DestDir: "{app}"; Flags: ignoreversion

Upvotes: 1

cosmin
cosmin

Reputation: 44

What you can do is add a global variable in your [Code] section

 [Code]

var
  ApplicationWasUninstalled: Boolean;

After that, in the InitializeUninstallProgressForm procedure you can set the global variable to 1 (Note: this function gets executed only if the user clicks Yes when they are prompted if they want to uninstall your application

procedure InitializeUninstallProgressForm();
begin
  ApplicationWasUninstalled := true;
end;

Moving on, you will check the value of ApplicationWasUninstalled in DeinitializeUninstall function

procedure DeinitializeUninstall();
begin
  if ApplicationWasUninstalled Then Begin
      //your code here
  end;
end;

Upvotes: 2

Related Questions