Is there an *official* way to detect Windows 11?
Asked Answered
L

6

16

The following question contains various ways to detect whether a system is running Windows 10 or Windows 11:

However, they all seem a bit "hackish" and brittle: checking file versions, build numbers, API availability, etc. Since the release of Windows 11 is just around the corner (ETA Oct 5), software vendors don't have much time left to prepare. Hence my question:

Has Microsoft published an officially recommended way for software developers to check for Windows 11, if you have a legitimate reason¹ for needing to know?


¹ I am aware that many programs think they need to check the OS version number, when, in fact, they should only be concerned about the availability of the specific feature they need. I fully support that. However, there are legitimate use cases (for example, a system management or software inventory tool), and I'd ask you to assume a legitimate use case for the purpose of this question.

PS: This question is deliberately not constrained to a particular technology; I consider any officially supported solution (using WinAPI, WMI, COM, .NET, ...) a valid answer.

Legislator answered 29/9, 2021 at 9:5 Comment(1)
++, double vote. for asking it to be the official one, there are so many ways to figure this out. Some take more time than others.Lizalizabeth
A
10

The question thread "Windows 11 build ver is still 10.0.22000.194" on Microsoft Q&A has received responses from two Microsoft employees. In the accepted answer, one says:

At least for now, OS build number 22000 is the standard that distinguishes Windows 10 from Windows 11.

And, in a comment below the answer, another adds:

This is correct. Anything above 10.0.22000.0 is Win 11. Anything below is Win 10.

This suggests that, at the time of that writing, a week after the public release of Windows 11 in October 2021, Microsoft had not yet published an official recommendation for software developers. Unless that changes, the 22000 build number seems to be the criterion one should rely on to draw the line between Windows 10 and 11.

Amphicoelous answered 11/11, 2021 at 2:29 Comment(4)
This no longer seems to be correct - I'm seeing build strings for windows 11 that are less than 22000, 6.2.9200.0Cicala
@David: That's because GetVersion(Ex) is lying to you. v6.2 is Windows 8.Legislator
@Legislator Is there a better call to make than GetVersion(Ex)?Cicala
@David: RtlGetVersion seems to be more accurate, see https://mcmap.net/q/104719/-c-how-to-detect-windows-10/87698. Personally, I query the registry.Legislator
C
3

The simplest way is to get the version of Kernel32.dll and if Major Version is 10 and Build Version is >= 22000 then you have Windows 11. There is nothing "hackish" in this approach.

See my code here: How can I find the Windows product name in Windows 11?

Coact answered 31/12, 2021 at 16:11 Comment(0)
P
2

Windows 11's architecture still basically uses Windows 10. There are plenty of leftover files and systems from Windows 10. Plenty of occurrences happened such as misnamed update names. Windows 11 still uses the Windows 10 version number as well. Now while command prompt is obsolete, it's still a core system of all Windows Systems. So I made a little something that can detect it using systeminfo (slow, ik)

From: https://www.lifewire.com/windows-version-numbers-2625171

systeminfo | findstr /i /c:"windows 11" > nul && {code here for windows 11} || {code here for not windows 11}

I know it may not be the solution you're looking for, and it's hard to implement batch script onto a modern app, but happy to help!

Polythene answered 10/11, 2021 at 6:20 Comment(0)
H
2

The accepted answer from john-hen is a great start. Unfortunately, Microsoft made things more complicated in September 2022 when they shipped the 22H2 update for Windows 11 with a build number of 22621.

You could do a simple >= 22000 as Elmue suggested, but that may break as Microsoft introduces other Windows server and client builds. For example, over Windows 10's lifetime its build numbers have ranged from 10240 to 19045, and multiple Windows Server releases (2016, 2019) fell into the middle of that range.

If you want to handle Windows server and client versions, you'll need a lookup table instead of a simple range. I'm using the lists of Windows Client Versions and Windows Server Versions from Wikipedia to maintain a "build number to display name" dictionary. If I don't find the current build number in the dictionary I just fallback to the reported OS version (typically, 10). The downside is that I have to remember to update the dictionary as new Windows versions are released, but it's manageable and worth it to me for an accurate OS identification.

private static readonly Dictionary<int, string> ModernWindowsBuildNumbers = new()
{
    // https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
    [22000] = "Windows 11 21H2",
    [22621] = "Windows 11 22H2",

    // https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions#Server_versions
    [14393] = "Windows Server 2016",
    [17763] = "Windows Server 2019",
    [20348] = "Windows Server 2022",
};

string kernel32 = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\System32\Kernel32.dll");
int buildNumber = FileVersionInfo.GetVersionInfo(kernel32).ProductBuildPart;
if (!ModernWindowsBuildNumbers.TryGetValue(buildNumber, out string displayName))
{
    // Report ProductName from registry instead.
    // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
}
Hulse answered 8/2, 2023 at 15:56 Comment(1)
As a better fallback than the registry ProductName, you can report the WMI Caption from Win32_OperatingSystem as MacTwistie mentions. On my system it returns "Windows 11 Pro". You can use ManagementObjectSearcher to run WMI queries in .NET.Hulse
E
1

How about this one-liner for dos? Powershell would be even easier.

FOR /F "tokens=1,2,3 delims= " %%A IN ('wmic os get Caption') DO IF %%B EQU Windows set WVer=%%B %%C

This will return "Windows 10" or "Windows 11"

If you want the full version, for example: PRO/Education etc then you can expand it.

FOR /F "tokens=1,2,3,4 delims= " %%A IN ('wmic os get Caption') DO IF %%B EQU Windows set WVer=%%B %%C %%D

Cheers

Ethiopic answered 9/8, 2022 at 3:22 Comment(0)
T
-1

Maybe we can use the following code:

auto fnWindows11OrGreater = []() -> bool {
    OSVERSIONINFOEX osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    osvi.dwMajorVersion = 10;
    osvi.dwMinorVersion = 0;
    osvi.dwBuildNumber = 22000;
    DWORDLONG dwlConditionMask = 0;
    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
    bool cond1 = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask);

    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    osvi.dwMajorVersion = 10;
    osvi.dwMinorVersion = 0;
    osvi.dwBuildNumber = 0;
    dwlConditionMask = 0;
    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER);
    VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
    bool cond2 = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask);

    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    osvi.dwMajorVersion = 10;
    osvi.dwMinorVersion = 0;
    osvi.dwBuildNumber = 0;
    dwlConditionMask = 0;
    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER);
    VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
    bool cond3 = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask);

    return cond1 || cond2  || cond3;
};
Tapdance answered 23/6, 2022 at 8:16 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Hoey
VerifyVersionInfo: This function has been deprecated for Windows 10.Engineering

© 2022 - 2025 — McMap. All rights reserved.