Search code examples
inno-setuppascalscript

Check function for UninstallDelete is called upon installation


I'm using Inno Setup to make my (un)installer. I want to make possibility to remove some "leftover" files after uninstall optionally, so I use [UninstallDelete] section with Check function for this. Function returns some value, but also shows some debug message. Something like this:

[UninstallDelete]
Type: filesandordirs; Name: "{app}\Plugins"; Check: ShouldRemovePlugins

[Code]
//...
var
  DelPlugins: Boolean;
//...
function ShouldRemovePlugins(): Boolean;
var text:string;
begin
  if(DelPlugins = true) then
    text := 'We should remove plugins'
  else
    text := 'We should not remove plugins';
  MsgBox(text, mbInformation, MB_OK);
  Result := DelPlugins;
end;

The thing is, that according to message box popping up, function is somehow called on install, not uninstall. So, question is - why so? Is it something about Inno Setup "workflow"?


Solution

  • It's determined during installation which uninstall tasks (including, but not limited to UninstallDelete entries) will be performed on uninstall.

    So your Check function will indeed by called during installation.


    See how processing UninstallDelete section is a step of installation:

    Once the actual installation process begins, this is the order in which the various installation tasks are performed:

    • [InstallDelete] is processed.
    • The entries in [UninstallDelete] are stored in the uninstall log (which, at this stage, is stored in memory).
    • The application directory is created, if necessary.
    • ...

    To delete files conditionally during uninstallation you have to code this explicitly in CurUninstallStepChanged event function.

    Use usUninstall or usPostUninstall step.