Search code examples
inno-setup

Inno Setup Scripted Constants in uninstaller


In my Inno Setup I call a second optional Installer. Which I would like to uninstall, if my app is uninstalled. But I have to get the uninstall path of a registry key, if I don't want to guess or ask a user.

Is it possible to get this registry key while uninstalling my app as a scripted variable for UninstallRun? As far as I understand UninstallRun is part of unins000.dat which is fully generated on setup, so no way there?


Solution

  • To use the [UninstallRun] section, you have to know the path on the install time. As the constants in all sections are resolved on the install time.

    If you do not know the path on install time, you have to use Pascal Script event function CurUninstallStepChanged. In the function, you can resolve the paths using Reg* support functions. Probably using RegQueryStringValue. Then you can execute the found binary using the Exec function.

    [Code]
    
    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    var
      Path: string;
    begin
      if CurUninstallStep = usUninstall then
      begin
        if RegQueryStringValue(..., ..., ..., Path) then
        begin
          Log(Format('Executing %s...', [Path]));
          Exec(Path, ...);
        end;
      end;
    end;