question

osvbnet avatar image
1 Vote"
osvbnet asked RLWA32-6355 commented

Version Compare Problem

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?

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered

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())

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

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 .

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, he had already posted the question and I had posted a sample : Check OS best practice
As he said he used My.Computer.Info.OSVersion, it reports correct version with a Manifest, like Environment.OSVersion.Version



0 Votes 0 ·

I find it peculiar that the OSVersion information returned from these classes include a revision number. The Version class documentation describes the revision number as "Revision: Assemblies with the same name, major, and minor version numbers but different revisions are intended to be fully interchangeable. A higher revision number might be used in a build that fixes a security hole in a previously released assembly." So while a revision number has meaning for an assembly in my opinion it doesn't seem relevant to an Operating System as a whole.

As a practical matter when considering OS version numbers there shouldn't be a disparity based on implementation details like the presence or absence of a revision number.

0 Votes 0 ·

From the sources, they seem to put Service Packs in Revision :

 Version v =  new Version(osvi.MajorVersion, osvi.MinorVersion, osvi.BuildNumber, (osviEx.ServicePackMajor << 16) |osviEx.ServicePackMinor);
0 Votes 0 ·
Show more comments

Hello, yeah I had that great solution, anyway my question here was just why compare version is strange?

If Version.op_GreaterThanOrEqual("10.0.18363", "10.0.18363.0")...

I thought "10.0.18363" and "10.0.18363.0" are the same by logic! :)

0 Votes 0 ·

Notwithstanding your expectations the Microsoft documentation for the version class says the following about comparisons --

For two versions to be equal, the major, minor, build, and revision numbers of the first Version object must be identical to those of the second Version object. If the build or revision number of a Version object is undefined, that Version object is considered to be earlier than a Version object whose build or revision number is equal to zero.

1 Vote 1 ·