1
votes

I have an installer that write this line in the Windows registry

[Registry]
Root: "HKCU"; Subkey: "SOFTWARE\W117GAMER"; ValueType: string; ValueName: "DSVersionL4D2"; ValueData: "{#MyAppVersion}"

taking into account that {#MyAppVersion} is defined and written when the program is installed

#define MyAppVersion "2.7"

I am constantly updating the installer, which is why some people have old installations, and when they update, old files that conflict are combined, so as not to uninstall the previous version, there is some way to read this registry before starting the installation.

  • First case: if the user has an old version, uninstall it and install the new version
  • Second case: if the user has the same version, tell them that they
    already have the latest version installed and cancel installation
  • Third case: if the user has a version installed and is going to
    install an old version, tell them that they already have the newest version of the program

I read previous posts but they only work with "GUID" or "appID" of the program, try to modify some lines of code but I could not get anything, if someone could help me I thank you in advance, sorry for my English I use a translator I am from Latin America

How to detect old installation and offer removal?

Inno Setup: How to automatically uninstall previous installed version?

2

2 Answers

1
votes

With use of RegQueryStringValue function and CompareVersion function from Compare version strings in Inno Setup (your question), you can do:

#define MyAppVersion "2.6"

[Code]

function InitializeSetup(): Boolean;
var
  InstalledVersion: string;
  VersionDiff: Integer;
begin
  Result := True;
  if not RegQueryStringValue(
           HKCU, 'Software\My Program', 'DSVersionL4D2', InstalledVersion) then
  begin
    Log('No installed version detected');
  end
    else
  begin
    Log(Format('Found installed version %s', [InstalledVersion]));
    VersionDiff := CompareVersion(InstalledVersion, '{#MyAppVersion}');
    if VersionDiff < 0 then
    begin
      MsgBox(
        Format('You have an old version %s installed, will uninstall it.', [
          InstalledVersion]),
        mbInformation, MB_OK);
      { Uninstall old version here }
    end
      else
    if VersionDiff = 0 then
    begin
      MsgBox(
        'You have this version installed already, cancelling installation.',
        mbInformation, MB_OK);
      Result := False;
    end
      else
    begin
      MsgBox(
        Format(
          'You have newer version %s installed already, cancelling installation.', [
          InstalledVersion]),
        mbInformation, MB_OK);
      Result := False;
    end;
  end;
end;

Just plug-in an uninstallation code from some of the answers you have linked in your question.


Though note that you do not need to write your own version registry value. There are DisplayVersion, VersionMajor and VersionMinor in the stnadard uninstall registry key.

0
votes

For anyone interested, I wrote a Windows DLL for Inno Setup than provides a simple way to do this if needed:

https://github.com/Bill-Stewart/UninsIS

The DLL requires Inno Setup 6 or newer because 1) it's Unicode only and 2) it requires parameters that specify 64-bit vs. 32-bit and administrative vs. non administrative installation modes.

The DLL can detect the current version that's installed and tell whether the installed version is older, newer, or the same so that you can do things like automatically uninstall only when downgrading (for example).