Search code examples
installationinno-setuppascalscriptdelphi

Check at runtime whether installer has Uninstallable=True?


I have this little piece of code that occurs at post-install step:

procedure CurStepChanged(CurStep: TSetupStep);
begin

  if CurStep = ssPostInstall then begin
    CreateSymbolicLink(ExpandConstant('{app}\Uninstall.vsf'), ExpandConstant('{cf}\Inno Setup\Carbon.vsf'), 0)
    CreateSymbolicLink(ExpandConstant('{app}\Uninstall.dll'), ExpandConstant('{cf}\Inno Setup\VclStylesinno.dll'), 0)
  end;

end;

I would like to accomodate it to create the symbolic links only if the installer has the Uninstallable=True, how I could chek that from pascal script?.

Note that I also pretend to determine it in scenarios like this: Uninstallable=not IsTaskSelected('task name').


Solution

  • Use a #define to store the value. You can check the value of it in the code section using ExpandConstant.

    Example:

    #define MyAppName "My Program"
    #define MyAppVersion "1.5"
    #define Uninstallable "no"
    
    [Setup]
    AppName={#MyAppName}
    AppVersion={#MyAppVersion}
    Uninstallable={#Uninstallable}
    
    [Code]  
    procedure CurStepChanged(CurStep: TSetupStep);
    begin    
      if CurStep = ssPostInstall then begin
        if LowerCase(ExpandConstant('{#Uninstallable}')) = 'yes' then
        begin
          CreateSymbolicLink(ExpandConstant('{app}\Uninstall.vsf'), ExpandConstant('{cf}\Inno Setup\Carbon.vsf'), 0);
          CreateSymbolicLink(ExpandConstant('{app}\Uninstall.dll'), ExpandConstant('{cf}\Inno Setup\VclStylesinno.dll'), 0);
        end;
      end;    
    end;