question

guliteb avatar image
0 Votes"
guliteb asked randomhiker27-2113 answered

Win32 API to detect Windows 11

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-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLaude avatar image
0 Votes"
LeonLaude answered

Hi @guliteb,

Here's another similar thread:
https://docs.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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

abbodi86-0005 avatar image
1 Vote"
abbodi86-0005 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 commented

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);

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The version of the OS reports something like 10.0.22000.184 regardless of which API you use. This is confirmed by the OS via 'ver' on the command-line. Major/Minor 10.0 is what Windows 10 also uses.

The OS itself is a bit mixed on what version of Windows it is. On 22000.184 (latest build) the OS still reports itself as "Windows 10 Pro" in this registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion - ProductName.

...that seems like bug they should fix before launch especially since reviewers or others might key off items like that to criticize the new OS as it just being a six-month update to Windows 10.

Using something like build >= 22000 seems like it should work for various reasons, but I'd like to see something official Microsoft on this. This normally would seem a completely reasonable assumption, but Microsoft hasn't ended major feature updates for Windows 10 yet (Win 10 21H2 due later this year). If that's the last feature update then this assumption seems good, but they've also created Win 11 min hardware requirements that splits their user base. Maybe they are hoping that users will just buy a new PC, but they may feel compelled to deliver feature updates to those Win 10 user over time rather than just security updates. Win 10 builds in the dev channel are at 21390 but appears updates ended in June, so maybe this is a reasonable assumption.

0 Votes 0 ·
Castorix31 avatar image Castorix31 randomhiker27-2113 ·

This is not an API, this reads a shared portion of the memory (some WMI functions do it too)
(and ver reads the registry)
Did you test USER_SHARED_DATA on Windows 11 ?

0 Votes 0 ·
randomhiker27-2113 avatar image
1 Vote"
randomhiker27-2113 answered

@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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.