Share via

Version Compare Problem

OSVBNET 1,401 Reputation points
2022-06-18T23:47:39.957+00:00

Hello,
It's strange that version compare does not work as intended here:

Dim MySearcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_OperatingSystem")
For Each MyQuery As ManagementObject In MySearcher.Get()
MyVersion = DirectCast(MyQuery("Version"), String)
Next
If Version.op_GreaterThanOrEqual(Version.Parse(MyVersion), Version.Parse(My.Computer.Info.OSVersion)) = True Then ...

The difference is a leading .0 although I don't know why this op_GreaterThanOrEqual is not showing by Visual Studio, kinda hidden or better way to compare 2 versions?

Developer technologies | VB
0 comments No comments

Answer accepted by question author
  1. Castorix31 91,871 Reputation points
    2022-06-19T09:25:13.587+00:00

    The ".0" is the Revision
    To compare with the string returned from Win32_OperatingSystem, you can build the version string from Environment.OSVersion.Version
    (with .Major.ToString() + "." + .Minor.ToString() + "." + .Build.ToString())

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RLWA32 52,441 Reputation points
    2022-06-19T10:57:39.237+00:00

    Unless the app is properly manifested both Computer.Info.OSVersion and Environment.OSVersion will produce strings that reflect the OS version lie (i.e., 6.2.9200.0 -- Windows 8). Tested on Win 10 21H1 and Win 8.1 when Targeting .Net Framework 4.

    The RtlGetVersion function exported from ntdll.dll will return OS version information that is correct and consistent with the version information returned by WMI .


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.