How to find default web browser in C#

1 Answer

0 votes
using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace workingframe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {

            string browserName = "iexplore.exe";

            using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"))
            {
                if (userChoiceKey != null)
                {
                    object progIdValue = userChoiceKey.GetValue("Progid");
                    if (progIdValue != null)
                    {
                        if (progIdValue.ToString().ToLower().Contains("chrome"))
                            browserName = "chrome.exe";
                        else if (progIdValue.ToString().ToLower().Contains("firefox"))
                            browserName = "firefox.exe";
                        else if (progIdValue.ToString().ToLower().Contains("safari"))
                            browserName = "safari.exe";
                        else if (progIdValue.ToString().ToLower().Contains("opera"))
                            browserName = "opera.exe";
                    }
                }
            }
            listBox1.Items.Add(browserName);
        }
    }
}

/*
run:

firefox.exe

*/

 



answered Mar 15, 2016 by avibootz

Related questions

1 answer 239 views
1 answer 278 views
1 answer 218 views
1 answer 196 views
1 answer 240 views
...