Search code examples
delphidelphi-10.3-riowindows-11

How to detect Windows 11 using Delphi 10.3.3


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)


Solution

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

    1. 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).

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

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

    4. (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.