11

I always used to check the windows versions by their major/minor build numbers. Strangely enough, Windows 7 and Server 2008 R2, both return the same major/minor version number combination.

Confirm this by typing ver into a command prompt

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
  • Try to look for capabilities instead. The majority of compatibility errors between versions of winows are there because someone depended on a specific version number. – idstam Sep 13 '09 at 18:56

5 Answers5

23

This works, and correctly detects many Windows Product Editions, including Windows XP, Windows 7 (Home, Professional), Windows Server 2003, and Windows Server 2008, and contains code that should identify Windows 8 and Windows Server 2012. It compiles on Delphi 2007, XE2, and XE3, and has been tested on WinXP Professional (SP2 and SP3), Windows 7 Pro 64-bit, and Windows Server 2003/2008 (32-bit 2003, 64-bit 2008). It should work on many others, but I don't have them available to test.

The code provides definitions under D2007 that are missing from the Windows unit, dynamically loads functions available in later Windows versions and uses them when they're available (but won't fail if they're not found). It contains a couple of rather outdated ways to detect Win95/ME/NT4; those are carryovers from the previous version of this code and are left for use (or removal) as you wish.

unit GetWinVersionInfo platform;

interface

uses
  Windows;

{$IF RTLVersion < 18}
{$MESSAGE Warn 'Not tested on Delphi versions before 2007!'}
{$IFEND}


function GetOSInfo: string;

var
  GetProductInfo: function (dwOSMajorVersion, dwOSMinorVersion,
                            dwSpMajorVersion, dwSpMinorVersion: DWORD;
                            var pdwReturnedProductType: DWORD): BOOL stdcall = nil;
var
  GetNativeSystemInfo: procedure(var SysInfo: TSystemInfo); stdcall = nil;

implementation

uses Registry, SysUtils;

{$IF RTLVersion < 19}

// Only used for pre-unicode versions of Delphi. Provides some definitions that
// Windows.pas doesn't provide in earlier versions of Delphi (most likely because
// they didn't exist them.
//
// No support for the W versions of the API definitions

type
  _OSVERSIONINFOEX = record
    dwOSVersionInfoSize : DWORD;
    dwMajorVersion      : DWORD;
    dwMinorVersion      : DWORD;
    dwBuildNumber       : DWORD;
    dwPlatformId        : DWORD;
    szCSDVersion        : array[0..127] of AnsiChar;
    wServicePackMajor   : WORD;
    wServicePackMinor   : WORD;
    wSuiteMask          : WORD;
    wProductType        : BYTE;
    wReserved           : BYTE;
  end;
  TOSVERSIONINFOEX = _OSVERSIONINFOEX;

const
  VER_NT_WORKSTATION    :Integer = 1;
  VER_SUITE_ENTERPRISE  :Integer = 2;
  VER_NT_SERVER         :Integer = 3;
  VER_SUITE_DATACENTER  :Integer = 128;
  VER_SUITE_PERSONAL    :Integer = 512;

const
  PRODUCT_UNDEFINED                           = $00000000;
  PRODUCT_ULTIMATE                            = $00000001;
  PRODUCT_HOME_BASIC                          = $00000002;
  PRODUCT_HOME_PREMIUM                        = $00000003;
  PRODUCT_ENTERPRISE                          = $00000004;
  PRODUCT_HOME_BASIC_N                        = $00000005;
  PRODUCT_BUSINESS                            = $00000006;  { Business }
  PRODUCT_STANDARD_SERVER                     = $00000007;
  PRODUCT_DATACENTER_SERVER                   = $00000008;
  PRODUCT_SMALLBUSINESS_SERVER                = $00000009;
  PRODUCT_ENTERPRISE_SERVER                   = $0000000A;
  PRODUCT_STARTER                             = $0000000B;
  PRODUCT_DATACENTER_SERVER_CORE              = $0000000C;
  PRODUCT_STANDARD_SERVER_CORE                = $0000000D;
  PRODUCT_ENTERPRISE_SERVER_CORE              = $0000000E;
  PRODUCT_ENTERPRISE_SERVER_IA64              = $0000000F;
  PRODUCT_BUSINESS_N                          = $00000010;
  PRODUCT_WEB_SERVER                          = $00000011;
  PRODUCT_CLUSTER_SERVER                      = $00000012;
  PRODUCT_HOME_SERVER                         = $00000013;
  PRODUCT_STORAGE_EXPRESS_SERVER              = $00000014;
  PRODUCT_STORAGE_STANDARD_SERVER             = $00000015;
  PRODUCT_STORAGE_WORKGROUP_SERVER            = $00000016;
  PRODUCT_STORAGE_ENTERPRISE_SERVER           = $00000017;
  PRODUCT_SERVER_FOR_SMALLBUSINESS            = $00000018;
  PRODUCT_SMALLBUSINESS_SERVER_PREMIUM        = $00000019;
  PRODUCT_HOME_PREMIUM_N                      = $0000001A;
  PRODUCT_ENTERPRISE_N                        = $0000001B;
  PRODUCT_ULTIMATE_N                          = $0000001C;
  PRODUCT_WEB_SERVER_CORE                     = $0000001D;
  PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT    = $0000001E;
  PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY      = $0000001F;
  PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING     = $00000020;
  PRODUCT_SERVER_FOUNDATION                   = $00000021;
  PRODUCT_HOME_PREMIUM_SERVER                 = $00000022;
  PRODUCT_SERVER_FOR_SMALLBUSINESS_V          = $00000023;
  PRODUCT_STANDARD_SERVER_V                   = $00000024;
  PRODUCT_DATACENTER_SERVER_V                 = $00000025;
  PRODUCT_ENTERPRISE_SERVER_V                 = $00000026;
  PRODUCT_DATACENTER_SERVER_CORE_V            = $00000027;
  PRODUCT_STANDARD_SERVER_CORE_V              = $00000028;
  PRODUCT_ENTERPRISE_SERVER_CORE_V            = $00000029;
  PRODUCT_HYPERV                              = $0000002A;
  PRODUCT_STORAGE_EXPRESS_SERVER_CORE         = $0000002B;
  PRODUCT_STORAGE_STANDARD_SERVER_CORE        = $0000002C;
  PRODUCT_STORAGE_WORKGROUP_SERVER_CORE       = $0000002D;
  PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE      = $0000002E;
  PRODUCT_STARTER_N                           = $0000002F;
  PRODUCT_PROFESSIONAL                        = $00000030;
  PRODUCT_PROFESSIONAL_N                      = $00000031;
  PRODUCT_SB_SOLUTION_SERVER                  = $00000032;
  PRODUCT_SERVER_FOR_SB_SOLUTIONS             = $00000033;
  PRODUCT_STANDARD_SERVER_SOLUTIONS           = $00000034;
  PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE      = $00000035;
  PRODUCT_SB_SOLUTION_SERVER_EM               = $00000036;
  PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM          = $00000037;
  PRODUCT_SOLUTION_EMBEDDEDSERVER             = $00000038;
  PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE        = $00000039;
  PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE   = $0000003F;
  PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT       = $0000003B;
  PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL       = $0000003C;
  PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC    = $0000003D;
  PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC    = $0000003E;
  PRODUCT_CLUSTER_SERVER_V                    = $00000040;
  PRODUCT_EMBEDDED                            = $00000041;
  PRODUCT_STARTER_E                           = $00000042;
  PRODUCT_HOME_BASIC_E                        = $00000043;
  PRODUCT_HOME_PREMIUM_E                      = $00000044;
  PRODUCT_PROFESSIONAL_E                      = $00000045;
  PRODUCT_ENTERPRISE_E                        = $00000046;
  PRODUCT_ULTIMATE_E                          = $00000047;
  PRODUCT_UNLICENSED                          = $ABCDABCD;

const
  PROCESSOR_ARCHITECTURE_INTEL            = 0;
  PROCESSOR_ARCHITECTURE_AMD64            = 9;
  SM_MEDIACENTER                          = 87;
  SM_SERVERR2                             = 89; {GetSystemMetrics for Win Server 2K3}

function GetVersionEx(var lpVersionInformation: TOSVersionInfo): BOOL; stdcall; overload;
  external kernel32 name 'GetVersionExA';
function GetVersionEx(var lpVersionInformationEx: TOSVERSIONINFOEX): BOOL; stdcall; overload;
  external kernel32 name 'GetVersionExA';

{$IFEND}

  // Not in the Windows.pas unit as of XE3
const
  PRODUCT_PROFESSIONAL_WMC                    = $00000067; {Professional with Media Center}

function GetOSInfo: string;
var
  NTBres, BRes: Boolean;
  OSVI: TOSVERSIONINFO;
  OSVI_NT: TOSVERSIONINFOEX;
  tmpStr: string;
  pdwReturnedProductType : DWORD;
  SI: TSystemInfo;
begin
  Result := 'Error';
  NTBRes := FALSE;
  try
    OSVI_NT.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFOEX);
    NTBRes := GetVersionEx(OSVI_NT);
    OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
    BRes := GetVersionEx(OSVI);
  except
    OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
    BRes := GetVersionEx(OSVI);
  end;
  if (not BRes) and (not NTBres) then
    Exit;
  Move( OSVI, OSVI_NT, SizeOf(TOSVersionInfo) );

  if Assigned(GetNativeSystemInfo) then
    GetNativeSystemInfo(SI)
  else
    GetSystemInfo(SI);

  case OSVI_NT.dwPlatformId of
     VER_PLATFORM_WIN32_NT:
       begin
         if OSVI_NT.dwMajorVersion <= 4 then
           Result := 'Windows NT ';
         if (OSVI_NT.dwMajorVersion = 5) then
         begin
           case OSVI_NT.dwMinorVersion of
             0: Result := 'Windows 2000 ';
             1: begin
                  Result := 'Windows XP ';
                  if (GetSystemMetrics(SM_MEDIACENTER) <> 0) then
                    Result := Result + 'Media Center';
                end;
             2: begin
                 if (OSVI_NT.wProductType = VER_NT_WORKSTATION) and
                    (SI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) then
                   Result := 'Windows XP Professional x64 '
                 else
                 begin
                   if GetSystemMetrics(SM_SERVERR2) <> 0 then
                     Result := 'Windows Server 2003 R2'
                   else
                     Result := 'Windows Server 2003 ';
                end;
             end;
           end;
         end;
         if (OSVI_NT.dwMajorVersion = 6) then
         begin
           case OSVI_NT.dwMinorVersion of
             0: begin
                  if OSVI_NT.wProductType = VER_NT_WORKSTATION then
                    Result := 'Windows Vista '
                  else
                   Result := 'Windows Server 2008 ';
                 end;
             1:  begin
                   if OSVI_NT.wProductType = VER_NT_WORKSTATION then
                     Result := 'Windows 7 '
                   else
                     Result := 'Windows Server 2008 R2 ';
                 end;
             2:  begin
                   if OSVI_NT.wProductType = VER_NT_WORKSTATION then
                     Result := 'Windows 8 '
                   else
                     Result := 'Windows Server 2012 ';
                 end;
           else
             Result := 'Unknown Windows version ';
           end;

           if Assigned(GetProductInfo) then
           begin
             GetProductInfo(OSVI_NT.dwMajorVersion,
                            OSVI_NT.dwMinorVersion,
                            0,
                            0,
                            pdwReturnedProductType);
             case pdwReturnedProductType of
               PRODUCT_PROFESSIONAL,
               PRODUCT_PROFESSIONAL_N:
                 tmpStr := 'Professional';
               PRODUCT_PROFESSIONAL_WMC:
                 tmpStr := 'Professional with Media Center';
               PRODUCT_BUSINESS,
               PRODUCT_BUSINESS_N:
                 tmpStr := 'Business Edition';
               PRODUCT_CLUSTER_SERVER:
                 tmpStr := 'Cluster Server Edition';
               PRODUCT_DATACENTER_SERVER:
                 tmpStr := 'Server Datacenter Edition (full installation)';
               PRODUCT_DATACENTER_SERVER_CORE:
                 tmpStr := 'Server Datacenter Edition (core installation)';
               PRODUCT_ENTERPRISE,
               PRODUCT_ENTERPRISE_N:
                 tmpStr := 'Enterprise Edition';
               PRODUCT_ENTERPRISE_SERVER:
                 tmpStr := 'Server Enterprise Edition (full installation)';
               PRODUCT_ENTERPRISE_SERVER_CORE:
                 tmpStr := 'Server Enterprise Edition (core installation)';
               PRODUCT_ENTERPRISE_SERVER_IA64:
                 tmpStr := 'Server Enterprise Edition for Itanium-based Systems';
               PRODUCT_HOME_BASIC,
               PRODUCT_HOME_BASIC_N:
                 tmpStr := 'Home Basic Edition';
               PRODUCT_HOME_PREMIUM,
               PRODUCT_HOME_PREMIUM_N:
                 tmpStr := 'Home Premium Edition';
               PRODUCT_HOME_PREMIUM_SERVER:
                 tmpStr := 'Home Premium Server Edition';
               PRODUCT_HOME_SERVER:
                 tmpStr := 'Home Server Edition';
               PRODUCT_HYPERV:
                 tmpStr := 'Hyper-V Server Edition';
               PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
                 tmpStr := 'Windows Essential Business Server Management Server Edition';
               PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
                 tmpStr := 'Windows Essential Business Server Security Server Edition';
               PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
                 tmpStr := 'Windows Essential Business Server Messaging Server Edition';
               PRODUCT_SERVER_FOR_SMALLBUSINESS:
                 tmpStr := 'Server for Small Business Edition';
               PRODUCT_SERVER_FOUNDATION:
                 tmpStr := 'Server Foundation';
               PRODUCT_SMALLBUSINESS_SERVER:
                 tmpStr := 'Small Business Server';
               PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                 tmpStr := 'Small Business Server Premium Edition';
               PRODUCT_STANDARD_SERVER:
                 tmpStr := 'Server Standard Edition (full installation)';
               PRODUCT_STANDARD_SERVER_CORE:
                 tmpStr := 'Server Standard Edition (core installation)';
               PRODUCT_STARTER:
                 tmpStr := 'Starter Edition';
               PRODUCT_STORAGE_ENTERPRISE_SERVER:
                 tmpStr := 'Storage Server Enterprise Edition';
               PRODUCT_STORAGE_EXPRESS_SERVER:
                 tmpStr := 'Storage Server Express Edition';
               PRODUCT_STORAGE_STANDARD_SERVER:
                 tmpStr := 'Storage Server Standard Edition';
               PRODUCT_STORAGE_WORKGROUP_SERVER:
                 tmpStr := 'Storage Server Workgroup Edition';
               PRODUCT_UNDEFINED:
                 tmpStr := 'An unknown product';
               PRODUCT_ULTIMATE,
               PRODUCT_ULTIMATE_N:
                 tmpStr := 'Ultimate Edition';
               PRODUCT_WEB_SERVER:
                 tmpStr := 'Web Server Edition';
               PRODUCT_WEB_SERVER_CORE:
                 tmpStr := 'Web Server Edition (core installation)';
               PRODUCT_UNLICENSED:
                 tmpStr := 'Unlicensed product'
             else
               tmpStr := '';
             end;{ pdwReturnedProductType }
             Result := Result + tmpStr;
             NTBRes := FALSE;
           end;{ GetProductInfo<>NIL }
         end;{ Vista }

         if OSVI_NT.dwMajorVersion >= 6 then
         begin
           if (SI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) then
             Result := Result + ' 64-bit'
           else if (SI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL) then
             Result := Result + ' 32-bit';
         end;

         if NTBres then
         begin
           if OSVI_NT.wProductType = VER_NT_WORKSTATION then
           begin
             case OSVI_NT.wSuiteMask of
               512: Result := Result + 'Personal';
               768: Result := Result + 'Home Premium';
             else
               Result := Result + 'Professional';
             end;
           end
           else if OSVI_NT.wProductType = VER_NT_SERVER then
           begin
             if OSVI_NT.wSuiteMask = VER_SUITE_DATACENTER then
               Result := Result + 'DataCenter Server'
             else if OSVI_NT.wSuiteMask = VER_SUITE_ENTERPRISE then
               Result :=  Result + 'Advanced Server'
             else
               Result := Result + 'Server';
           end{ wProductType=VER_NT_WORKSTATION }
           else
           begin
             with TRegistry.Create do
               try
                 RootKey := HKEY_LOCAL_MACHINE;
                 if OpenKeyReadOnly('SYSTEM\CurrentControlSet\' +
                                    'Control\ProductOptions') then
                   try
                     tmpStr := UpperCase(ReadString('ProductType'));
                     if tmpStr = 'WINNT' then
                       Result := Result + 'Workstation';
                     if tmpStr = 'SERVERNT' then
                       Result := Result + 'Server';
                   finally
                     CloseKey;
                   end;
               finally
                 Free;
               end;
             end;{ wProductType<>VER_NT_WORKSTATION }
           end;{ NTBRes }
         end;{ VER_PLATFORM_WIN32_NT }
     VER_PLATFORM_WIN32_WINDOWS:
       begin
         if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 0) then
         begin
           Result := 'Windows 95 ';
           if OSVI.szCSDVersion[1] = 'C' then
             Result := Result + 'OSR2';
         end;
         if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 10) then
         begin
           Result := 'Windows 98 ';
           if OSVI.szCSDVersion[1] = 'A' then
             Result := Result + 'SE';
         end;
         if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 90) then
           Result := 'Windows Me';
       end;{ VER_PLATFORM_WIN32_WINDOWS }
     VER_PLATFORM_WIN32s:
       Result := 'Microsoft Win32s';
  else
    Result := 'Unknown';
  end;{ OSVI_NT.dwPlatformId }
end;{ GetOSInfo }

initialization
  @GetProductInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
                                     'GetProductInfo');

  @GetNativeSystemInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
                                         'GetNativeSystemInfo');

end.

Sample use:

program GetWinVersionInfoTest;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  GetWinVersionInfo;

begin
  WriteLn(GetOSInfo);
  ReadLn;
end.
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 4
    Windows 7 is MajorVersion = 6, MinorVersion = 1 – mmmm Mar 19 '10 at 12:28
  • @Ken This code still needs to update assign dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion before calling GetProductInfo – David Heffernan Mar 28 '13 at 13:31
  • @David: Yeah, I was updating that when I saw your comment. I was looking at the issue with Win7. It's just the first two that need to be assigned, according to [MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724429%28v=vs.85%29.aspx), and there's no value available to assign them. (`dwOSMajorVersion` and `dwOSMinorVersion` can be obtained from `OSVI_NT`.) – Ken White Mar 28 '13 at 13:39
  • Might be nice to remove all the duplicated declarations (Windows.pas has them all) and switch to Unicode API. – David Heffernan Mar 28 '13 at 13:40
  • @David: The older versions of Windows.pas don't have them, though. – Ken White Mar 28 '13 at 13:44
  • @David: I can get rid of the `_OSVERSIONINFOEX`, though. Unicode versions of Delphi then pick up the `W` versions automatically. – Ken White Mar 28 '13 at 13:46
  • OK. I think I'd just lose them for simplicity. The last two or three versions have them. Your call. No worries. As for GPI, why delete the four locals dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion and instead pass the four values found from OSVI_NT directly. Would be nice to lose those four locals I think. – David Heffernan Mar 28 '13 at 13:51
  • 1
    @David: I'll work on cleaning it up some. I posted this in 2009, and had forgotten about it until I saw my name in the thread this morning and looked back at it. I'm in the middle of something now, but will try and revisit in the next couple of days to do some more cleanup. :-) – Ken White Mar 28 '13 at 17:15
  • 2
    @David: Updated to remove unnecessary local variables, define types and functions for D2007 but not replace them in higher versions that define them already, and provide a 'platform specific' warning. Tested in D2007/XE2/XE3 - I don't have any other versions available right now to test. Could still be improved to dynamically load `GetProductInfo` instead of statically, but I don't think I'll bother with it. :-) Thanks for the suggestions. – Ken White Mar 29 '13 at 01:31
  • Ken! Please tell what is the function of "NTBres" and "BRes". – Rubi Halder Apr 03 '13 at 19:01
  • @RobHalder: They hold the return values of the two calls to `GetVersionEx`. If they're both false in the `if (not NTBres) and (not BRes)` test, both calls to `GetVersionInfoEx` failed and we can't do anything. If after that, `NTBres` is true, the call succeeded with `TOSVersionInfoEx`, and we have additional fields available (the big case statement); after that `case` is done, we set the flag to false to prevent it going into the second `if NTBres` block (the one after the test for 32/64 bit). We don't need that block to run, because we've got all the info we need. – Ken White Apr 03 '13 at 19:56
  • @Ken White - Where are constants like VER_NT_WORKSTATION and PROCESSOR_ARCHITECTURE_AMD64 defined? My Delphi XE cannot find them. I had to define them manually. – Gabriel Jul 01 '13 at 12:31
  • @Altar: Right here. In the code I posted. :-) Inside the block starting with `{$IF RTLVersion < 19}`, right below the start of the `implementation` section. They're only needed for pre-Unicode versions of Delphi; they're in the Windows unit in the Unicode versions of Delphi (2009 and up). It's right there in the code, in a comment. – Ken White Jul 01 '13 at 12:36
  • @Ken White - I just found it :) Because the code was marked with {$IF RTLVersion < 19} ( non-unicode versions of Delphi) and I have Delphi XE I removed the entire block. But actually that block IT IS needed under Delphi XE. Thanks anyway – Gabriel Jul 01 '13 at 12:46
  • Confirmation - With the small modification described above, it works on Delphi XE. It correctly shows Win7 and Win 8. – Gabriel Jul 01 '13 at 12:49
  • `GetNativeSystemInfo` does not return a value (BOOL). https://msdn.microsoft.com/en-us/library/windows/desktop/ms724340(v=vs.85).aspx – kobik May 17 '17 at 14:53
  • 1
    @kobik: Fixed for correctness. The return value wasn't used in the code, so it didn't change anything but the declaration. Thanks for pointing that out. – Ken White May 17 '17 at 15:24
9

GetVersionEx. There is a chart of the version numbers and their associated editions here. Notice that the product type is different between 2008 R2 and Windows 7.

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
  • 4
    I like to use the JCL (Jedi Class Library) which maintains an enumerated type, and it uses GetVersionEx plus other things, to decode down to a simple enumerated type for each major shipped/boxed operating system configuration and product type (Windows Server 2008 R2, XP, Win7, etc etc). – Warren P May 27 '11 at 12:31
2

This is a good starting point, but you'll need to pay attention to all the fields in the osVerInfo structure, not just the major & minor versions.

JosephStyons
  • 57,317
  • 63
  • 160
  • 234
1

Well, GetVersionEx is nice, but it can be a little more complex than that, especially when users are playing with the compatibility settings.
Read on this excellent post by Gabr...
And look at this previous SO question.

Community
  • 1
  • 1
Francesca
  • 21,452
  • 4
  • 49
  • 90
1

This can be done now (under newer versions of Delphi) with TOsVersion: http://docwiki.embarcadero.com/Libraries/XE7/en/System.SysUtils.TOSVersion

Example of code: TOSVersion.Major

Full answer here: How to detect 32/64 platform?

Community
  • 1
  • 1
Gabriel
  • 20,797
  • 27
  • 159
  • 293