简体   繁体   中英

7zip latest version pragmatically?

I want to compare 7zip.exe version installed on client machine with the latest version released.

At present, I am able to fetch the latest version number by downloading source code from page URL https://www.7-zip.org/download.html .

Here is my code. Is there any API (Seems there is no API available)/ other better solution to read 7zip latest version programmatically?

Dim sourceString As String = New System.Net.WebClient().DownloadString("https://www.7-zip.org/download.html")

Here's a way to do it, but it's susceptible to changes

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM