Monthly Archives: September 2014

Getting Installed Browsers and Version C#

I ran into a few posts that solved the problem of getting the installed browsers on a Windows machine and getting the version that were very helpful.

Getting Chrome and Firefox version locally, C#

Finding All Installed Browsers in Windows XP and Vista – beware 64bit!

These snippets were very helpful. So now I will hand it combined to you on a silver platter as a downloadable Console App.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Win32;


namespace GetAllInstalledBrowsers
{
class Program
{
static void Main(string[] args)
{
foreach (Browser browser in GetBrowsers())
{
Console.WriteLine(string.Format("{0}: \n\tPath: {1} \n\tVersion: {2} \n\tIcon: {3}", browser.Name, browser.Path, browser.Version, browser.IconPath));
}
Console.ReadKey();
}


public static List<Browser> GetBrowsers()
{
RegistryKey browserKeys;
//on 64bit the browsers are in a different location
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
string[] browserNames = browserKeys.GetSubKeyNames();
var browsers = new List<Browser>();
for (int i = 0; i < browserNames.Length; i++)
{
Browser browser = new Browser();
RegistryKey browserKey = browserKeys.OpenSubKey(browserNames[i]);
browser.Name = (string)browserKey.GetValue(null);
RegistryKey browserKeyPath = browserKey.OpenSubKey(@"shell\open\command");
browser.Path = (string)browserKeyPath.GetValue(null).ToString().StripQuotes();
RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
browser.IconPath = (string)browserIconPath.GetValue(null).ToString().StripQuotes();
browsers.Add(browser);
if (browser.Path != null)
browser.Version = FileVersionInfo.GetVersionInfo(browser.Path).FileVersion;
else
browser.Version = "unknown";
}
return browsers;
}
}


internal static class Extensions
{
///
/// if string begins and ends with quotes, they are removed
///
internal static String StripQuotes(this String s)
{
if (s.EndsWith("\"") && s.StartsWith("\""))
{
return s.Substring(1, s.Length - 2);
}
else
{
return s;
}
}
}


class Browser
{
public string Name { get; set; }
public string Path { get; set; }
public string IconPath { get; set; }
public string Version { get; set; }
}
}

If you run this code you will get results that resemble this:

Mozilla Firefox:
Path: C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Version: 31.0
Icon: C:\Program Files (x86)\Mozilla Firefox\firefox.exe,0
Google Chrome:
Path: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Version: 37.0.2062.124
Icon: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe,0
Internet Explorer:
Path: C:\Program Files\Internet Explorer\iexplore.exe
Version: 10.00.9200.16521 (win8_gdr_soc_ie.130216-2100)
Icon: C:\Program Files\Internet Explorer\iexplore.exe,-9

Happy coding!

Advertisements