Determine Windows Version with InnoSetup

Posted on August 25, 2020 at 1:39 pm

If you need to install a file on say XP or Vista and newser:

[Files]
Source: MyDllForVistaAndNewer.dll; Dest: {app}\MyDll.dll; MinVersion: 6.0
Source: MyDllForOldWindows.dll; Dest: {app}\MyDll.dll; OnlyBelowVersion: 6.0

Here are some functions to use inside [Code]:

function IsWindowsVersionOrNewer(Major, Minor: Integer): Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);
  Result :=
    (Version.Major > Major) or
    ((Version.Major = Major) and (Version.Minor >= Minor));
end;
 
function IsWindowsXPOrNewer: Boolean;
begin
  Result := IsWindowsVersionOrNewer(5, 1);
end;
 
function IsWindowsVistaOrNewer: Boolean;
begin
  Result := IsWindowsVersionOrNewer(6, 0);
end;
 
function IsWindows7OrNewer: Boolean;
begin
  Result := IsWindowsVersionOrNewer(6, 1);
end;
 
function IsWindows8OrNewer: Boolean;
begin
  Result := IsWindowsVersionOrNewer(6, 2);
end;
 
function IsWindows10OrNewer: Boolean;
begin
  Result := IsWindowsVersionOrNewer(10, 0);
end;

Example usage:

function InitializeSetup: Boolean;
begin
  if not IsWindowsVistaOrNewer then
  begin 
    MsgBox(
      'This program was not tested on Windows XP and older, proceed with caution.',
      mbCriticalError, MB_OK);
  end;  
 
  Result := True;
end;

Source: https://stackoverflow.com/a/38292498

Receive updates via email

Other Posts

Updated Posts