Detecting Windows 11

Hi. I’m trying to detect Windows 11 using an older version of Xojo (2018) without using plugins.

GetVersionExA and GetVersionExW doesn’t work so I found this on the forum but need some help converting it to work with Xojo.

Private Declare Function RtlGetVersion Lib "NTDLL" (ByRef lpVersionInformation As Long) As Long

Public Sub NativeGetVersion(ByRef plMajorVer As Long, ByRef plMinorVer As Long)
   Dim tOSVw(&H54) As Long
   tOSVw(0) = &H54 * &H4
   RtlGetVersion tOSVw(0)
   plMajorVer = tOSVw(1)
   plMinorVer = tOSVw(2)
End Sub

Dim lOSMajorVer As Long
Dim lOSMinorVer As Long
NativeGetVersion lOSMajorVer, lOSMinorVer

bIsWin10 = (lOSMajorVer >= 10)

Can anyone lend a hand or provide a better solution?

Thanks!

Marketing may call it Windows 11, but under the hood, it is just a Windows 10 with a higher build number.

At least that is how I check it in my plugins.

1 Like

Anything >= 10.0.22000 is currently a “Windows 11”

1 Like

Thanks. Yes using GetVersionExA and GetVersionExW it reports major 6 and minor 2 and build 9200 for both Windows 10 (build 19045) and Windows 11 (build 22631) so that’s why I was hoping I could use RtlGetVersion instead but don’t know how to convert the code above to work in Xojo and also find the correct build as reported in System Information.

The information between GetVersionExW and RtlGetVersion seem to be very similar.

Attached is Example 2-2 from my ~1200 page book on Windows Declares Xojo Windows API2 Book that shows the information that Christian and Rick mention about Windows version numbers.

Example2-02-API2.zip (8.3 KB)

Here is a screengrab of the retrieved information with GetVersionEx on my Windows 11 computer:
Declare2-2 Screen Grab

3 Likes

That worked! Thanks Eugene. I suddenly realised why… because the code was roughly the same as what I had but I was building to 32 bit not 64 bit. Is there any reason nowadays to build for 32bit if I want to support Windows 7 and above? Or shall I just build 64bit do you think?

Let me “interfere” here, pardon. I have not a single 32bit user for years now. So they are not relevant. I have 2% of Windows 7 users, and they were warned that they will be left without updates.

My path is Win 10+ support ASAP. Not even Win 8+

2 Likes

If you just want to determine if Windows 11 (or 10) you can call pwsh.exe (or poweshell.exe)


sh.ExecuteMode = Shell.ExecuteModes.synchronous

sh.TimeOut = 10000

Sh.Execute("pwsh.exe -command (Get-CimInstance Win32_OperatingSystem).Caption -Match 'Windows 11' "   )


sh.Result will Return True or False
2 Likes

Does everyone agree with Rick that I can safely ditch Win32 and deploy only Win64 or are there still many Win32 users out there and/or other factors to consider?

The last 32bit x86 Desktop CPU was the Pentium4 in 2002. That’s 22 years ago. There were also some short lived Atom ones in 2010 (14 years ago) for simple applications used in some toy-like-computers I’m not counting on for sure. Surely there are some 32bit computer in some live museum running somewhere, but I ignore those drops in the ocean. Over time, since 2020, the 32bit (desktop, not counting embedded options) dropped to virtually zero. I even don’t track such data anymore from my users since 2020 when Microsoft stopped to produce and release Windows 32bit versions (last one was Win 10 20H1 = 10.0.19041). You may produce 32bit versions due to personal reasons, they run in the 64bit OS VM, but not due to needing because there’s a desktop market that can’t be ignored out there.

1 Like

Hi Denise,

Yes, I agree with Rick that you can likely ditch Windows 32-bit applications and start new projects in 64-bit mode. Most of my development is Windows and Linux. All work that I have with new Windows and Linux applications/servers are 64-bit. There is older equipment that occasionally uses 32-bit, but this is the exception-to-the-rule.

1 Like

Thanks for all your help!

1 Like