B4J Code Snippet CheckWin11

Just a simple trick I use to detect Windows 11 using Shell. This Sub returns True if the version is larger or equals to 22000.493
There is a known bug in JDK to detect Windows 11 version.

B4X:
Public Sub CheckWin11 As ResumableSub
    Try
        Dim shl As Shell
        shl.Initialize("shl", "cmd", Array As String("/C", "ver"))
        shl.Run(3000) 'set a timeout of 3 seconds
        Wait For (shl) shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        If Success And ExitCode = 0 Then
            'Log(StdOut) ' Microsoft Windows [Version 10.0.22000.652]
            Dim out As String = StdOut.Trim
            If out.Contains("Microsoft Windows") And out.Contains("10.0.") Then
                out = out.SubString2(out.IndexOf("10.0.") + 5, out.Length - 1)
                Dim version As Double = out
                Return version >= 22000.493
            End If
        Else
            Log("Error: " & StdErr)
        End If
    Catch
        Log(LastException)
    End Try
    Return False
End Sub

Usage:
Here is a sample how I use in my application.
B4X:
Sub ShowOS
    LblPOSName.Text = Main.PRODUCT_NAME & " running on " & OSName
    If OSName = "Windows 10" Then
        Wait For (CheckWin11) Complete (Result As Boolean)
        If Result Then
            LblPOSName.Text = Main.PRODUCT_NAME & " running on Windows 11"
        End If
    End If
End Sub

Sub OSName As String
    Return GetSystemProperty("os.name", "")
End Sub

Edit: Code updated
 
Last edited:

Magma

Expert
Licensed User
Longtime User
Last edited:

aeric

Expert
Licensed User
Longtime User
As CMD/DOS Freak...

some extra cmd commands:

slower, but more specific:

a faster way...

only version






Here is what I got:

Bash:
Microsoft Windows [Version 10.0.22000.652]
(c) Microsoft Corporation. All rights reserved.

C:\Users\aeric>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22000 N/A Build 22000

C:\Users\aeric>wmic os get Caption,CSDVersion /value


Caption=Microsoft Windows 11 Pro
CSDVersion=




C:\Users\aeric>wmic os get version
Version
10.0.22000


C:\Users\aeric>
 

Magma

Expert
Licensed User
Longtime User
Here is what I got:

Bash:
Microsoft Windows [Version 10.0.22000.652]
(c) Microsoft Corporation. All rights reserved.

C:\Users\aeric>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22000 N/A Build 22000

C:\Users\aeric>wmic os get Caption,CSDVersion /value


Caption=Microsoft Windows 11 Pro
CSDVersion=




C:\Users\aeric>wmic os get version
Version
10.0.22000


C:\Users\aeric>
sorry:
wmic os get Caption,Version /value
 
Top