Detect if running Windows 11

Started by MrBcx, March 31, 2025, 09:47:10 PM

Previous topic - Next topic

MrBcx

The built-in BCX function OSVERSION returns 21 if Windows 11 is detected.

The following demo shows that, along with an alternative way of
detecting Windows 11 by calling an undocumented function in NtDll.dll
OSVERSION uses the same undocumented function in a slightly different way.

Written to be compiled as a GUI.

FUNCTION winmain
    MSGBOX IIF$(isWinEleven() = TRUE, "Windows 11 Detected", "Windows 11 NOT Detected")
    MSGBOX IIF$(OSVERSION = 21, "Windows 11 Detected", "Windows 11 NOT Detected")
    FUNCTION = 0
END FUNCTION



FUNCTION isWinEleven () AS BOOL
    LOCAL OsInfoEx AS OSVERSIONINFOEXW
    OsInfoEx.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEXW)
    RtlGetVersion(lib "NtDll.dll", &OsInfoEx)
    IF ((OsInfoEx.dwMajorVersion = 10) AND (OsInfoEx.dwBuildNumber >= 22000)) OR OsInfoEx.dwMajorVersion > 10 THEN
        FUNCTION = TRUE
    ELSE
        FUNCTION = FALSE
    END IF
END FUNCTION

Vortex

#1
This method was proposed by Nidud, author of the Asmc assembler :

DIM hMod AS HMODULE
DIM pNTHeaders AS PIMAGE_NT_HEADERS

hMod = GetModuleHandle("kernel32.dll")

pNTHeaders = (PIMAGE_NT_HEADERS)((LPBYTE)hMod + ((PIMAGE_DOS_HEADER)hMod)->e_lfanew)

PRINT "Major Operating System Version =", pNTHeaders->OptionalHeader.MajorOperatingSystemVersion
PRINT "Minor Operating System Version =", pNTHeaders->OptionalHeader.MinorOperatingSystemVersion

My output :

Major Operating System Version = 6
Minor Operating System Version = 1

The minor version of Windows 11 is 0.

Vortex

Kevin's methods is reliable. It looks like that even the information stored in the registry cannot be trusted :

PRINT "Product Name = ", _
REGSTRING$(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName")

Quin

Cool trick, thanks for sharing!
And yeah Vortex, you're right, the Registry still says Windows 10 :D
-Quin.
GitHub

MrBcx

FYI:

I am running Windows 11 pro.  when I type VER in a CLI window, it returns: 
Microsoft Windows [Version 10.0.26100.3476]

Anthropic's CLAUDE responds:

That version number indicates you're running a recent build of Windows 11,
not Windows 10 despite the "10.0" prefix in the version string.

The version number "10.0.26100.3476" breaks down as:

    "10.0" - This is the major version number that Microsoft has maintained even through Windows 11 (Windows 11 is internally still version 10.0)
    "26100" - This is the build number that indicates Windows 11 (Windows 11 builds typically start at 22000)
    "3476" - This is the revision number

Your build (26100) appears to be from a very recent Windows 11 update or preview build. The high build number
suggests you're running one of the latest versions of Windows 11, possibly from the Windows Insider program.

MrBcx responds:  Correct, I am on the latest Windows Insider Preview build.