Home > Software engineering >  Detect Windows 11 with .NET Framework or Windows API
Detect Windows 11 with .NET Framework or Windows API

Time:09-18

In .NET Framework, to get the OS version you can use Environment.OSVersion with the Major and Minor values telling you the version of Windows (i.e 6.1 = Windows 7, 10.0 = Windows 10). Even though Windows 11 has been released (dev and beta channels) for over a month now, the documentation has not been updated to mention how to detect Windows 11.

For Windows API, GetVersion has been deprecated forever and even the version helper APIs only go up to IsWindows10OrGreater. Is there a simple check to figure out the major Windows version, in particular Windows 11? Someone had a similar question but for Delphi (How to detect Windows 11 using Delphi 10.3.3) and the accepted answer was all hacks. Why the hell is it so difficult for Microsoft to provide a simple API to just return the current system version? GetVersion should never have been deprecated.

CodePudding user response:

This most likely isn't perfect, but it's a workaround I've been using for a bit:

Environment.OSVersion.Version.Build >= 22000;

Windows 11 starts at build number 22000 and Windows 10 ends roughly at build number 21390, so this will only detect Windows 11 builds as far as I'm aware.

Do check whether it even is a Windows system in the first place though, another OS might have a higher build number.

CodePudding user response:

You can use RtlGetVersion() in ntdll.dll, which is not subject to OS compatibility manifestation, like GetVersion/Ex() and other similar APIs are (and especially since there is no supportedOS GUID defined for Windows 11 yet).

  • Related