Skip to content

Instantly share code, notes, and snippets.

@mistic100
Last active January 3, 2024 22:22
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save mistic100/acb3484464e29f28279c to your computer and use it in GitHub Desktop.
Save mistic100/acb3484464e29f28279c to your computer and use it in GitHub Desktop.
[InnoSetup] Prevent install if newer version is already installed
#define AppId "{INSERT HERE YOUR GUID}"
#define AppName "My App"
#define AppVersion "1.7"
[CustomMessages]
english.NewerVersionExists=A newer version of {#AppName} is already installed.%n%nInstaller version: {#AppVersion}%nCurrent version:
[Code]
// find current version before installation
function InitializeSetup: Boolean;
var Version: String;
begin
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1', 'DisplayVersion') then
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1', 'DisplayVersion', Version);
if Version > '{#AppVersion}' then
begin
MsgBox(ExpandConstant('{cm:NewerVersionExists} '+Version), mbInformation, MB_OK);
Result := False;
end
else
begin
Result := True;
end
end
else
begin
Result := True;
end
end;
@rickbot-dot
Copy link

Not working when installing only for the current user, maybe because of line 12 and 14 using HKEY_LOCAL_MACHINE which therefore makes me still able to install an older version.

@andrelp
Copy link

andrelp commented Aug 31, 2023

You can use HKEY_AUTO to automatically switch to HKEY_CURRENT_USER if the installer runs in non-admin mode

@rickbot-dot
Copy link

You can use HKEY_AUTO to automatically switch to HKEY_CURRENT_USER if the installer runs in non-admin mode

Been waiting for an answer for months. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment