Hope S Hope S - 1 year ago 135
C# Question

How to find default web browser using C#?

Is there a way I can find out the name of my default web browser using C#?
(Firefox, Google Chrome, etc..)

Can you please show me with an example?

Answer Source

You can look here for an example, but mainly it can be done like this:

internal string GetSystemDefaultBrowser()
    string name = string.Empty;
    RegistryKey regKey = null;

        //set the registry key we want to open
        regKey = Registry.ClassesRoot.OpenSubKey("HTTP\\shell\\open\\command", false);

        //get rid of the enclosing quotes
        name = regKey.GetValue(null).ToString().ToLower().Replace("" + (char)34, "");

        //check to see if the value ends with .exe (this way we can remove any command line arguments)
        if (!name.EndsWith("exe"))
            //get rid of all command line arguments (anything after the .exe must go)
            name = name.Substring(0, name.LastIndexOf(".exe") + 4);

    catch (Exception ex)
        name = string.Format("ERROR: An exception of type: {0} occurred in method: {1} in the following module: {2}", ex.GetType(), ex.TargetSite, this.GetType());
        //check and see if the key is still open, if so
        //then close it
        if (regKey != null)
    //return the value
    return name;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download