Search code examples
windowsinstallationinno-setuppascalscript

Check if the current OS is Windows 8.1 using Inno Setup Pascal Script


I would like to determine whether the current OS is Windows 8.1.

I know this could be solved analyzing the NT version number (6.3) of the current Windows version, but I don't know how to do it under Pascal script.

Pseudo-Code:

// Occurs when the installer initializes.
function InitializeSetup(): Boolean;
begin
  if IsWindows81 then
    begin
      Result := IsKBInstalled('KB2919355');
      if not Result then
        MsgBox('Windows Update package "KB2919355" not found.', mbError, MB_OK);
      end;
    else
      begin
        Result := True
      end;
end;

Solution

  • Windows 8.1 is Windows version 6.3.

    The easiest is to check the return value of the GetWindowsVersion function, which is $MMNNBBBB (Major, miNor, Build).

    function IsWindows81OrLater: Boolean;
    begin
      Result := (GetWindowsVersion >= $06030000);
    end;
    

    If you want to check for Windows 8.1 only, use:

    function IsWindows81: Boolean;
    begin
      Result := (GetWindowsVersion >= $06030000) and (GetWindowsVersion <= $0603FFFF);
    end;
    

    See also Determine Windows version in Inno Setup.