Last active
January 3, 2024 22:22
-
-
Save mistic100/acb3484464e29f28279c to your computer and use it in GitHub Desktop.
[InnoSetup] Prevent install if newer version is already installed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
You can use HKEY_AUTO to automatically switch to HKEY_CURRENT_USER if the installer runs in non-admin mode
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
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.