The method used by MS up to Windows 10 is RtlGetVersion
(then comparing Major/Minor from Operating System Version)
(on Windows 11, APIs from Winbrand.dll)
A test :
Dim ovi As RTL_OSVERSIONINFOW = New RTL_OSVERSIONINFOW With {
.dwOSVersionInfoSize = Marshal.SizeOf(GetType(RTL_OSVERSIONINFOW))
}
Dim ntStatus As UInteger = RtlGetVersion(ovi)
Console.WriteLine("Major version : {0} - Minor version : {1} - Build Number : {2}", ovi.dwMajorVersion.ToString(),
ovi.dwMinorVersion.ToString(), ovi.dwBuildNumber.ToString())
with :
<DllImport("Ntdll.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function RtlGetVersion(ByRef lpVersionInformation As RTL_OSVERSIONINFOW) As UInteger
End Function
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure RTL_OSVERSIONINFOW
Public dwOSVersionInfoSize As UInteger
Public dwMajorVersion As UInteger
Public dwMinorVersion As UInteger
Public dwBuildNumber As UInteger
Public dwPlatformId As UInteger
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)>
Public szCSDVersion As String
End Structure