I realize this question has been answered before but nothing with recent Windows OS.
I have modified my code to work for all versions up to Windows 10 but it doesn’t see Windows 11 as being different.
#elseif TargetWin32
dim OS_CODE as Integer
os = "Windows"
//try to be more specific of windows version
Soft Declare Sub GetVersionExA Lib "Kernel32" ( info As Ptr )
Soft Declare Sub GetVersionExW Lib "Kernel32" ( info As Ptr )
Dim info As MemoryBlock
If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
info = New MemoryBlock( 20 + (2 * 128) )
info.Long( 0 ) = info.Size
GetVersionExW( info )
Else
info = New MemoryBlock( 148 )
info.Long( 0 ) = info.Size
GetVersionExA( info )
End If
OS_CODE=info.Long(4)*100+info.long(8)
Select Case OS_CODE
Case 400
os = "Windows 95/NT 4.0"
Case 410
os = "Windows 98"
Case 490
os = "Windows Me"
Case 300 To 399
os = "Windows NT 3.51"
OS_CODE=30
Case 500
os = "Windows 2000"
Case 501
os = "Windows XP"
Case 502
os = "Windows Server 2003"
Case 600
os = "Windows Vista"
Case 601
os = "Windows 7"
case 602 // 32bit Windows 8.1 and 10
dim s as new shell
s.execute("ver")
dim res as string = s.Result
if val(mid(res,30,2)) = 10 then
os = "Windows 10"
else
os = "Windows 8/8.1"
end if
case 603 // 64 bit Windows 8.1
os = "Windows 8/8.1"
case 1000 // 64 bit Windows 10
os = "Windows 10/11"
case else
os = "Unknown Windows build - " + str(OS_CODE)
End Select
I would suspect the reported MajorVersion is incorrect leading to the ToString function generating the unexpected value. Can’t complain though, the documentation says that Xojo doesn’t officially support Windows 11
Your code has many problems, if you use the shell, why bother with the API? But your shell code is going to fail if the os is on other languaje.
Using only the MajorVersion and MinorVersion is wrong, 10.0 is vallid for 5 diferent Versions:
-Windows 11
-Windows 10
-Windows Server 2022
-Windows Server 2019
-Windows Server 2016
Instead of the “OS_CODE”, get the dwMajorVersion, dwMinorVersion, dwBuildNumber and dwPlatformId:
Dim dwMajorVersion As UInt32 = info.UInt32Value(4)
Dim dwMinorVersion As UInt32 = info.UInt32Value(8)
Dim dwBuildNumber As UInt32 = info.UInt32Value(12)
Dim dwPlatformId As UInt32 = info.UInt32Value(16)