2

I am using GetVersionEx to get the Operating System. But I don't know why it's reporting Windows 10 as Windows 8? I know it's deprecated but I can't find another solution.

switch (osinfo.dwMajorVersion)
    {
    case 5:
        if (osinfo.dwMinorVersion == 0)
        {
            sysinfo = "Windows 2000 ";
        }
        else if (osinfo.dwMinorVersion == 1)
        {
            sysinfo = "Windows XP ";
        }
        else if (osinfo.dwMinorVersion == 2)
        {
            sysinfo = "Windows XP ";
        }
        break;
    case 6:
        if (osinfo.dwMinorVersion == 3)
        { 
            sysinfo = "Windows 8.1 ";
        }
        else if (osinfo.dwMinorVersion == 2)
        {
            sysinfo = "Windows 8 ";
        }
        else if (osinfo.dwMinorVersion == 1)
        {
            sysinfo = "Windows 7 ";
        }
        else {
            sysinfo = "Windows Vista ";
        }
        break;
    case 10:
        sysinfo = "Windows 10 ";
        break;
    default:
        sysinfo = "Unknown OS ";
    }
Lynx
  • 147
  • 2
  • 8
  • 1
    https://learn.microsoft.com/en-us/windows/win32/sysinfo/getting-the-system-version – Rietty Oct 08 '19 at 21:29
  • 1
    [Windows Version Number Notes](https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version) Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10, refer to [Targeting your application for Windows.](https://learn.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1) –  Oct 08 '19 at 21:32

1 Answers1

1

From the documentation:

GetVersionExA function

[GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions]

With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

There is a lot of detail here, but somewhat difficult to wade through. At the bottom, it presents the concept that getting the OS version is not a great thing to do:

Remarks

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself. For more information, see Operating System Version.

That link suggests the BOOL IsOS(DWORD dwOS) function where the parameter is one of about 40 choices like OS_WIN95ORGREATER, OS_WIN2000TERMINAL, OS_PROFESSIONAL, etc.

Or there is the GetProductInfo() which appears to have even more detailed results.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
wallyk
  • 56,922
  • 16
  • 83
  • 148