Getting Chrome and Firefox version locally, C#
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
Rizowski
I like dogs. Long snowboard rides in the dark and interesting problems to solve. I aim for high quality code with sufficient tests that people aren't calling me at 4 AM wondering why something is down. I like helping others learn and seeking to find the next best thing that can make my job easier and faster. Project I work on: eslint-watch - A watch flag for eslint plex-2-discord - Plex webhooks to discord riz-bot - My discord admin that grants granular permissions and gaming stat lookup Tid Bits Observables are cool. I still like lodash. destructuring and spread. Postgres over mongo or couch. Elk Stack does nice things.
Updated on June 04, 2022Comments
-
Rizowski almost 2 years
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 can tell Chrome and Firefox do not store that information in registry.
Thanks in advance.
-
Rizowski over 11 yearsWhat OS version did you test this on?
-
Michael Liu over 11 yearsWindows 7, 64-bit. I used the default platform target of x86 for the console app (otherwise, I probably would've had to specify the Wow6432Node registry node for Firefox, since Firefox is 32-bit).
-
Angelo Vargas about 11 yearsThe chrome.exe for me (Windows 7 64bit) was on HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER, might as well check both locations just in case, right?
-
Michael Liu about 11 years@trukin: If that's the case, then yes. Apparently Chrome offers the option of either per-user or per-machine installation.