0

I'm trying to retrieve the version number of various installed applications and then perform an action if they are lower than a certain value. For example:

Dim regKey As RegistryKey
        Dim ver As ???????
        regKey = Registry.LocalMachine.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX")
        ver = regKey.GetValue("DisplayVersion")
                MessageBox.Show(ver)
            If ver < 11.4.402.287 Then
            'Install updated version of software in question
        End If
        regKey.Close()

How could I define Ver to be able to easily do a greater/less than check? I've tried:

Dim ver as integer
Dim ver as decimal

Both of these return "Additional information: Conversion from string "11.4.402.287" to type 'Decimal' is not valid."

1
  • You'll probably need to parse the string into the major/minor/build portions and make your determination based on that (most likely only the first two number - major and minor versions - will be of interest. In the example above, 11 would be the major version number and 4 the minor.) Commented Oct 24, 2012 at 21:27

2 Answers 2

1

Simple Parse and check assuming you are looking at first two components:

Dim va = Ver.split("."c)
If va(0) < 11 OrElse (va(0) = 11) and va(1) < 4) Then 
    'Install updated ....
End If
Sign up to request clarification or add additional context in comments.

1 Comment

This definitely looks like the simplest approach. :)
0

A regex for this might look something like:

(?<major>\d+)(\.(?<minor>\d+)(\.(?<revision>\d+)(\.(?<build>\d+))?)?)?

You could then extract the version numbers using groups:

Dim l_version As Regex = New Regex("(?<major>\d+)(\.(?<minor>\d+)(\.(?<revision>\d+)(\.(?<build>\d+))?)?)?")
Dim l_versionMatch As Match = l_version.Match( "1.2.3" )

Dim l_major As String = l_versionMatch.Groups("major").Value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.