At our company we have decided the ONLY reliable way to detect the Windows version is to shell out to a command prompt and run "systeminfo". The reasoning is as follows.
In Microsoft's official documentation for Version API helper functions ( https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version ), it will NOT detect Windows 11, and Microsoft recommends testing for the presence/absence of a feature instead. For this reason we believe Microsoft will deliberately try to block programmers from getting an accurate version.
LW001 suggests checking for build #22000, but one user said it doesn't work, and another said it was weak. In light of (1) above, it doesn't seem a safe long term solution.
"systeminfo", on the other hand, is a Microsoft tool built-in to Windows that is specifically designed to assist with debugging a PC's configuration. As such, unlike (1), it necessarily must report correct Windows version information.
The only downside is that (3) takes a couple of seconds to run, but we are doing that invisibly in the background while showing our splash screen. We actually implemented the check in Delphi instead of .Net, but the basic outline is the same and looks like this:
BatFile := MakeTempPath('Win11Check-%d.bat');
ResultFile := MakeTempPath('Win11Result-%d.txt');
SaveStringToFile(BatFile, AnsiString('systeminfo>"' + ResultFile + '"'));
LaunchProcessAndWaitForExit(BatFile, '', True);
Results := LoadWideStringFromFile(ResultFile);
OsName := GetStringBetween(Results, 'OS Name', #13) + ' 0';
We create a batch file that runs systeminfo and dumps the result into a result file. We run that batch file invisibly in the background and wait for the process to terminate. Then we read the result file contents as a string. Finally, we grab the Windows version by finding the substring between "OS Name" and the next carriage return. There's actually a colon and some spaces still in the string but you get the idea... we just look for an integer... "10" vs "11"... or even "2019" or "2022" in case of Windows Server.
In summary, Microsoft believes that every time it implements a new operating system, it can just emulate the previous one perfectly and even emulate its old version numbers. In practice, programmers have repeatedly found compatibility problems specific to a version (in our case we are seeing a repeatable and definite problem specifically with Windows 11). Thus, we believe Microsoft's strategy (as mentioned in (1) at the top) is wrong, and that "systeminfo" is our best bet in reliably detecting the current Windows.