我想将客户端计算机上安装的7zip.exe版本与最新发布的版本进行比较。
目前,我可以通过从页面URL https://www.7-zip.org/download.html下载源代码来获取最新版本号。
这是我的代码。 是否有任何API(似乎没有可用的API)/其他更好的解决方案以编程方式读取7zip最新版本?
Dim sourceString As String = New System.Net.WebClient().DownloadString("https://www.7-zip.org/download.html")
这是一种方法,但是很容易发生变化
Private Function GetInstalledVersion() As Single
Dim version As Single = Nothing
Using root = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
Using key = root.OpenSubKey("Software\7-Zip", False)
Dim appPath As String = CStr(key.GetValue("Path"))
Dim appVersion = FileVersionInfo.GetVersionInfo(Path.Combine(appPath, "7z.exe"))
If Not Single.TryParse(appVersion.ProductVersion, version) Then
Console.WriteLine("Unable to retrieve installed version")
End If
Return version
End Using
End Using
End Function
Private Function GetWebVersion() As Single
Dim r As Regex = New Regex("(?<=Download 7-Zip ).*?(?= )")
Dim web = New Net.WebClient().DownloadString("https://www.7-zip.org/download.html")
Dim version As Single = Nothing
If Not Single.TryParse(r.Match(web).Value, version) Then
Console.WriteLine("Unable to retrieve web version")
End If
Return version
End Function