0

I wonder if there's any API or way to detect if an application is running on Windows 11.

While searching I found these apis but it lack a specific for Windows 11, there's an IsWindowsXXOrGreater but I'm not sure which version to check and how to use it.

I also found some similar questions on StackOverflow but referring to Windows 10, I tried some of the answers but I still couldn't get a 'conclusive' way to check for it.

This show '10' when tested on Windows 11:

    NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
    OSVERSIONINFOEXW osInfo;

    *(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");

    if (NULL != RtlGetVersion)
    {
        osInfo.dwOSVersionInfoSize = sizeof(osInfo);
        RtlGetVersion(&osInfo);
        qDebug() << "version: " << (double)osInfo.dwMajorVersion;

        MessageBoxA(NULL, std::to_string((double)osInfo.dwMajorVersion).c_str(), NULL, 0);
    }
Cesar
  • 41
  • 2
  • 5
  • 16
  • [`IsWindowsVersionOrGreater`](https://learn.microsoft.com/en-us/windows/win32/api/versionhelpers/nf-versionhelpers-iswindowsversionorgreater)? Listed in that link you provided. – Some programmer dude Dec 01 '22 at 16:57
  • 2
    @Daniela "*I also found some similar questions on StackOverflow but referring to Windows 10, I tried some of the answers but I still couldn't get a 'conclusive' way to check for it*" - really? There are **numerous** questions whose answers refer to specific APIs that can get the true Windows version, and there are plenty of those queations/answers referring to Windows 11 specifically. So, what *exactly* did you try that is not working for you? – Remy Lebeau Dec 01 '22 at 17:16
  • Great thread here [IsWindowsVersionOrGreater is Useless](https://social.msdn.microsoft.com/Forums/en-US/2c7f9e1e-2fff-4c4f-80eb-9cd452468c90/iswindowsversionorgreater-is-useless?forum=windowsgeneraldevelopmentissues) – Richard Critten Dec 01 '22 at 17:16
  • If the other answers failed, the app is probably missing the manifest file declarations as Remy Lebeau mentioned. See VerifyVersionInfo remarks, Windows 10 section - https://learn.microsoft.com/en-us/windows/win32/api/Winbase/nf-winbase-verifyversioninfoa – Dave S Dec 01 '22 at 17:21
  • The remarks section of many API calls includes some important warnings and limitations. It's the "fine print" of the contract that takes away the promises of the large print :) – Dave S Dec 01 '22 at 17:28
  • 2
    @Someprogrammerdude that function, and related functions, all lie in Windows 8.1 onward if the app is not manifested as supporting the specific Windows version being checked. Only a few APIs (namely NetServerGetInfo(), RtlGetVersion(), RtlGetNtVersionNumbers(), etc) tell the truth regardless of whether a manifest is present or not. – Remy Lebeau Dec 01 '22 at 17:31
  • @RemyLebeau Note that there's no separate **supportedOS** manifest value for Windows 11. – Jonathan Potter Dec 01 '22 at 19:39
  • @RemyLebeau I have added the API I have tested on Windows 11, what API did you mention that can get the true windows version? – Cesar Dec 01 '22 at 20:10
  • 1
    @JonathanPotter right, and that is intentional on Microsoft's part: https://stackoverflow.com/questions/68240304/ But, once you have access to a valid build number (via manifest or otherwise), you can differentiate between Win10 (< 21996) and Win11 (>= 21996). – Remy Lebeau Dec 01 '22 at 20:24

1 Answers1

2

Windows 11 is an extension of Windows 10, so it does not increment the major/minor version numbers reported by RtlGetVersion() and other similar APIs, and does not add a new <supportedOS> guid in application manifests.

Windows 11 is still reported as v10.0, as shown in the OSVERSIONINFOEXW documentation:

The following table summarizes the version information that is returned by supported versions of Windows. Use the information in the "Other" column or build number to distinguish between operating systems with identical version numbers.

Operating system Version number dwMajorVersion dwMinorVersion Other
Windows 11 10.0 10 0 wProductType == VER_NT_WORKSTATION
Windows Server 2022 10.0 10 0 wProductType != VER_NT_WORKSTATION
Windows Server 2019 10.0 10 0 wProductType != VER_NT_WORKSTATION
Windows 10 (all releases) 10.0 10 0 wProductType == VER_NT_WORKSTATION

So, you need to use the build number to differentiate between Windows 10 and 11. Windows 11 is v10.0 build 21996 and higher.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • `MessageBoxA(NULL, std::to_string((double)osInfo.dwBuildNumber).c_str(), NULL, 0);` prints 0 on my Win11 computer and on Win10 it prints a version, – Cesar Dec 01 '22 at 20:37
  • @Daniela Why are you converting the number to a `double`? Just use it as-is, as `opeator<<` and `to_string()` have suitable overloads: `qDebug() << "version: " << osInfo.dwMajorVersion;` ... `std::to_string(osInfo.dwBuildNumber)`. – Remy Lebeau Dec 01 '22 at 20:43
  • 1
    Still print 0 as `MessageBoxA(NULL, std::to_string(osInfo.dwBuildNumber).c_str(), NULL, 0);` – Cesar Dec 01 '22 at 20:44
  • @Daniela Then there is something wrong with your setup, because Windows 11 is not v10.0.0. Maybe your `OSVERSIONINFOEXW` is using the wrong alignment? Are you declaring that struct type yourself in your own code, or are you using the definition provided in the Windows SDK? – Remy Lebeau Dec 01 '22 at 20:47