Win32 API to detect Windows 11

guliteb 36 Reputation points
2021-09-10T08:29:15.213+00:00

I need a Win32-based way to detect OS version (esp. Windows 11). Things like WMI, .NET, and UWP APIs are complex to access from Win32.

I tried GetProductInfo(). But it returns same value on Win10 and Win11.

Any comment is appreciated.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,419 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. abbodi86 3,776 Reputation points
    2021-09-10T14:36:23.31+00:00

    Check the build number, if it's 22000 or higher then it's Windows 11

    even if Windows 10 got new build number, it will be lower

    2 people found this answer helpful.
    0 comments No comments

  2. randomhiker27 21 Reputation points
    2021-09-17T14:08:00.207+00:00

    @Castorix31 , API or not that distinction doesn't matter in this case. There is no reason to believe that the major/minor is being misreported by some parts of the OS in this case.

    While some APIs can lie to you (like GetVersionEx), all Microsoft's tools that display major/minor version agree including WMI (Win32_OperatingSystem object), winver, and msinfo. More importantly, Microsoft's own download sites also agree the major/minor is 10.0 for build 22000. When you download the Windows 11 Insider SDK it is listed as something like 10.0.22000.168-preview. You can view version info on the 'Details' tab of C:\windows\System32\kernel32.dll and see it clearly reports a 10.0.22000.x version for Beta channel (track scheduled for Oct 5th release).

    22000 is supposed to be major/minor 10.0 at this point based on all those data points above. The questions are:
    * Will 10.0 be used for the October 5th Gold release based on build 22000 (seems likely at this point)?
    * Will Win32 developers be given a documented way to differentiate between Windows 10 and 11, or report compatibility through the manifest?
    * Will content in the Windows 11 registry be updated to reflect the OS is actually Windows 11 instead of Windows 10?

    Ideally Win32 developers don't have to scrape strings from WMI objects, call into Windows Runtime Libraries, spawn a process and scrape text, or other heavier weight options to clearly identify what OS we are running in. At this point it seems like checking build >= 22000 is the only light-weight option we've been given, and it's not clear to me if that is a future-proof solution.

    1 person found this answer helpful.
    0 comments No comments

  3. Leon Laude 85,651 Reputation points
    2021-09-10T08:36:34.893+00:00

    Hi @guliteb ,

    Here's another similar thread:
    https://learn.microsoft.com/en-us/answers/questions/464971/supportedos-id-for-windows-11.html

    Since Windows 11 is yet to be released, new APIs/other developer references haven't yet been released, in this case I would suggest you to wait for some time until they are released.

    ----------

    If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!

    Best regards,
    Leon

    0 comments No comments

  4. Castorix31 81,636 Reputation points
    2021-09-12T08:29:36.607+00:00

    Maybe you can try to read the USER_SHARED_DATA structure
    This test works on my Windows 10 OS (1909), but I have no Windows 11 to test =>

    // Copy here the KUSER_SHARED_DATA structure from ntddk.h or MSDN
    #define MM_SHARED_USER_DATA_VA 0x7FFE0000
    #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA)
    
    // Test code
    ULONG nBuildNumber = USER_SHARED_DATA->NtBuildNumber;
    ULONG nMajorVersion = USER_SHARED_DATA->NtMajorVersion;
    ULONG nMinorVersion = USER_SHARED_DATA->NtMinorVersion;
    WCHAR wsMessage[255] = L"";     
    swprintf(wsMessage, L"Build Number : %d\r\nMajor Version : %d\r\nMinor Version : %d", nBuildNumber, nMajorVersion, nMinorVersion);
    MessageBox(NULL, wsMessage, L"Information", MB_OK | MB_ICONINFORMATION);