Search code examples
windowsinno-setuppascalscript

Refresh shell associations in Inno Setup conditionally (only if a function is checked)


As the title says how can I make that Inno Setup use the:

[Setup]
ChangesAssociations=yes 

Only when a certain function is checked:

function installation: Boolean;
begin
  Result := install.Checked; { only if this is checked }
end;

function portable: Boolean;
begin
  Result := porta.Checked;
end;

I need that association doesnt get called when I simply extract the portable version of my software.


Solution

  • Instead of using ChangesAssociations directive, call SHChangeNotify WinAPI function conditionally from CurStepChanged(ssPostInstall):

    [Code]
    
    const
      SHCNE_ASSOCCHANGED = $08000000;
      SHCNF_IDLIST = $00000000;
    
    procedure SHChangeNotify(wEventID: Integer; uFlags: Cardinal; dwItem1, dwItem2: Cardinal);
      external 'SHChangeNotify@shell32.dll stdcall';
    
    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssPostInstall then
      begin
        if installation then
        begin
          SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
        end;
      end;
    end;
    

    This is what ChangesAssociations=yes internally does.


    Partially based on: Inno Setup refresh desktop.