Developer note: Windows 8.1 returns the internal OS version as 6.2 when calling the Win32 API function GetVersion, unless you mark your application Windows 8.1 compatible

Posted: (EET/GMT+2)

 

Note for all Windows developers, especially those using Win32 native APIs. For a long time, you could have used the GetVersion and GetVersionEx API functions to get the operating system version. However, as of Windows 8.1, both of these API functions have been marked deprecated.

From now on, you should start using the Version Helper APIs. These new API functions are called IsWindowsXPOrGreater, IsWindows7OrGreater, IsWindowsServer etc.

Then, something more special regarding Windows 8.1, which is internally versioned as 6.3 (Windows 8 was version 6.2): if you call the GetVersion(Ex) API function from a Win32 application without doing anything else, Windows 8.1 will report itself to be Windows 8. That is, the information you get from the API indicates Windows 6.2, and not 6.3 as you would guess. This is change made because of application compatibility.

Here's a quick example in C++:

#include "stdafx.h"
#include 

// disables the error "Error C4996: 'GetVersion': was declared deprecated"
#pragma warning (disable : 4996)

int _tmain(int argc, _TCHAR* argv[])
{
  DWORD version = GetVersion();
  printf("Version raw value: %d\r\n", version);
	
  DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version)));
  DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version)));
  DWORD build = 0;

  if (version < 0x80000000)
    build = (DWORD)(HIWORD(version));

  printf("Windows version: %d.%d.%d\r\n",
          majorVersion, minorVersion, build);

  return 0;
}

If you would run this application, it would return information like this:

Version raw value: 602931718
Windows version: 6.2.9200

How do you get the real, correct OS version? Firstly, you could use the new APIs like IsWindows8Point1OrGreater. However, you can mark your application to be Windows 8.1 compatible by adding a new value to your application's manifest file.

This is done with the "compatibility" section of the manifest file, to which you must add an XML element to match the GUID of Windows 8.1. The correct GUID is "1f676c76-80e1-4239-95bb-83d0f6d0da78". Here's an example:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application> 
            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        </application> 
    </compatibility>

The moral of the story: sometimes, a function return value might not immediately be what you expect.