Can Inno Setup respond differently to a new install and an update?

后端 未结 2 1577
心在旅途
心在旅途 2020-12-06 15:28

My InnoSetup script opens a web page (with the user\'s default browser) at the end of the install process:

[Run]
Filename: http://example.com; Flags: shellex         


        
相关标签:
2条回答
  • 2020-12-06 15:51

    The answer by @AndreasRejbrand won't work, if user chooses to install the executable to a different location than the last time.

    You can query installer-specific Inno Setup registry keys:

    #define AppId "your-app-id"
    #define SetupReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\" + AppId + "_is1"
    #define SetupAppPathReg "Inno Setup: App Path"
    
    [Setup]
    AppId={#AppId}
    ...
    
    [Run]
    Filename: "https://www.example.com/"; Flags: shellexec; Check: not IsUpgrade
    ...
    
    [Code]
    
    function IsUpgrade: Boolean;
    var
      S: string;
    begin
      Result :=
        RegQueryStringValue(HKLM, '{#SetupReg}', '{#SetupAppPathReg}', S) or
        RegQueryStringValue(HKCU, '{#SetupReg}', '{#SetupAppPathReg}', S);
    end;
    

    For an example how to use IsUpgrade in [Code] section, see
    Excludes part of Code section in ssPostInstall step if installation is update in Inno Setup

    Check this is your "AppId" contains a left-curly-bracket:
    Checking if installation is fresh or upgrade does not work when AppId contains a curly bracket

    0 讨论(0)
  • 2020-12-06 15:52

    Yes, this is easy to do with scripting.

    Just write

    [Run]
    Filename: "http://example.com"; Flags: shellexec; Check: NotAnUpdate
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = wpInstalling then
        IsUpdate := FileExists(ExpandConstant('{app}\TheFileNameOfMyApp.exe'));
    end;
    
    function NotAnUpdate: Boolean;
    begin
      result := not IsUpdate;
    end;
    
    0 讨论(0)
提交回复
热议问题