我正在尝试检索各种已安装应用程序的版本号,然后在低于某个值时执行操作。例如:
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()
我如何定义Ver能够轻松地执行更大/更少的检查?我试过了:
Dim ver as integer
Dim ver as decimal
这两个都返回“附加信息:从字符串转换”11.4.402.287“输入'十进制'无效。”
答案 0 :(得分:1)
简单解析并检查假设您正在查看前两个组件:
Dim va = Ver.split("."c)
If va(0) < 11 OrElse (va(0) = 11) and va(1) < 4) Then
'Install updated ....
End If
答案 1 :(得分:0)
这方面的正则表达式可能类似于:
(?<major>\d+)(\.(?<minor>\d+)(\.(?<revision>\d+)(\.(?<build>\d+))?)?)?
然后,您可以使用组提取版本号:
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