Upgrades

From ISXKB

Jump to: navigation, search

When upgrading an application, it is a good idea to hide the directory selection and program group selection pages to stop users changing the details once it has already been installed and potentially orphaning files. If you're using Inno Setup 5.3.3 or later, this is easily accomplished:

[Setup]
DisableDirPage=auto
DisableProgramGroupPage=auto

If you are using an older version, then there is no built in method to detect if you are installing fresh, or upgrading an existing install with the same AppID, so you will need to make use of a small function that looks up the previous installation directory and returns TRUE if it's an upgrade or FALSE if it's not:

function IsUpgrade(): Boolean;
var
   sPrevPath: String;
begin
  sPrevPath := '';
  if not RegQueryStringValue(HKCU, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1', 'UninstallString', sPrevpath) then
    RegQueryStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1', 'UninstallString', sPrevpath);
  Result := (sPrevPath <> '');
end;

This first checks the uninstall key in HKEY_CURRENT_USER, and if that fails, checks HKEY_LOCAL_MACHINE. (Typically you only need to check one or the other of these, depending on your PrivilegesRequired setting; checking both is only required for PrivilegesRequired=none or if you have had mixed admin/lowest installations in the past using the same AppId, neither of which is recommended.)

Bear in mind that this snippet uses ISPP, but if you do not have this available, replace {#emit SetupSetting("AppID")} with the AppID used by your setup.

Warning: If your AppID consists of a GUID (so you have a leading {{) or if you use other constants within it, then you will also need to call ExpandConstant:

 ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1')

You can then use the return value of this function to hide the install directory and program group selection pages. This stops the user from installing the same app into multiple locations and generally making a mess... :o)

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;
  if IsUpgrade() then
  begin
    if PageID = wpSelectDir then Result := True;
    if PageID = wpSelectProgramGroup then Result := True;
  end;
end;

Nothing else is needed to do an upgrade installation as Inno handles the rest for you automatically (provided you have specified appropriate Flags on your install entries).

In Inno 5.3.3 and above, you can check the value of WizardForm.PrevAppDir to determine the previous install folder and determine if an upgrade is being performed (however note that this is not available in InitializeSetup; InitializeWizard is the earliest that it can be called):

function IsUpgrade(): Boolean;
var
   sPrevPath: String;
begin
  sPrevPath := WizardForm.PrevAppDir;
  Result := (sPrevPath <> '');
end;

See also

Personal tools
Ads: