Getting Chrome and Firefox version locally, C#

后端 未结 1 1981
死守一世寂寞
死守一世寂寞 2021-02-13 14:39

I am just using regular C# not ASP.NET. I was wondering if I could get the version for Chrome and Firefox. I know for IE you can get the version through registry. From what I ca

相关标签:
1条回答
  • 2021-02-13 15:10

    If you know the full path of an application, then you can use the System.Diagnostics.FileVersionInfo class to get the version number.

    Here's a simple console application that reads the installation paths of Chrome and Firefox from the registry, and outputs their version numbers:

    using System;
    using System.Diagnostics;
    using Microsoft.Win32;
    
    class Program
    {
        static void Main(string[] args)
        {
            object path;
            path = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "", null);
            if (path != null)
                Console.WriteLine("Chrome: " + FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion);
    
            path = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe", "", null);
            if (path != null)
                Console.WriteLine("Firefox: " + FileVersionInfo.GetVersionInfo(path.ToString()).FileVersion);
        }
    }
    

    Sample output:

    Chrome: 24.0.1312.52
    Firefox: 16.0.2
    
    0 讨论(0)
提交回复
热议问题