Reputation: 956
I use TOSVersion.ToString function (uses SysUtils) to detect Windows version. However this is what I get in Windows11:
Windows 10 (Version 10.0, Build 21996, 64-bit Edition)
Is there any reliable way to detect Windows 11? I'm using Delphi 10.3.3.
UPDATE: Windows 11 is officially released and I tried again. Here is what I get:
Windows 10 (Version 10.0, Build 22000, 64-bit Edition)
Upvotes: 5
Views: 6257
Reputation: 8138
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.
See my code here: How can I find the Windows product name in Windows 11?
Upvotes: 0
Reputation: 56
Except the very weak, atleast for me, solution of considering Windows 10 builds greater than 22000, such as Windows 11, the only solution I found which is actually working is the WMIs Win32_OperatingSystem class - Caption
property.
On my dev Win10 machine, it gives the following string: Microsoft Windows 10 Pro
.
On my another dev machine, with Win11 installed, the same function gives: Microsoft Windows 11 Pro
.
The difference is in string values - "10" vs "11"- but this is at least something far better than the "build greater than" solution.
C# and C++ work well.
Upvotes: 1
Reputation: 28517
Official major version number for Windows 11 is 10.
The official build number for the public preview of Windows 11 is 10.0.22000.168
Earlier builds:
- 10.0.22000.71
- 10.0.22000.65
- 10.0.22000.51
If you want to detect Preview versions, earliest build number was 10.0.22000.51 Windows 11 version history
TOSVersion
relies on some hard coded names and logic to return OS name. You will have to implement your own detection, copy and modify TOSVersion
record or make wrapper around it, where you can use existing logic for older versions and implement check based on Windows 11 build number to detect Windows 11.
For other general issues and approaches in detecting OS version you can refer to AmigoJack's answer
Upvotes: 4
Reputation: 6099
As Remy pointed out: using the WinAPI you risk of being in some compatibility mode, resulting in getting a version reported that is lower than the actual.
One alternative is to check the file version of expected files, i.e.
%windir%\system32\ntoskrnl.exe
or%windir%\explorer.exe
using GetFileVersionInfo()
and VerQueryValue()
- the HiWord(dwFileVersionLS)
should be 22000
or higher (according to Windows NT build/release number).
Another is to look in the Registry under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\
at the text values CurrentBuild
and CurrentBuildNumber
, checking if the highest of both is 22000
or higher.
David already wrote a detailled answer in Checking Windows version on W10 with even more alternatives, although concentrating on the high/low version numbers, not the build. But WMI might help.
(This only works in retrospective with confirmed knowledge.) Check which API exports are available: the idea is that specific functions were introduced with specific Windows releases/versions, so if importing fails for one you know you're on a version below. An outdated example and an outdated list of minimum versions per function will give you an idea. Now you "only" have to find out which new functions are introduced with Windows 11.
Those are all not bulletproof, but you could combine them and then draw conclusions. And after all that you can still try your approach to parse texts instead of relying on numbers only. It also shows how easily you can manipulate your system into reporting different versions as per which method is used.
Upvotes: 4