Get Browser Or Default - CSharp Operating System

CSharp examples for Operating System:Browser

Description

Get Browser Or Default

Demo Code


using Microsoft.Win32;
using System.Linq;
using System.Collections.Generic;
using System;/*from ww w.j ava2s  .  co m*/

public class Main{
        public static BrowserDetail GetBrowserOrDefault(string name)
        {
            var installedBrowsers = GetInstalledBrowsers().ToArray();
            var browser = installedBrowsers.FirstOrDefault(b => 
                b.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (browser != null)
            {
                return browser;
            }

            return installedBrowsers.FirstOrDefault(b => b.IsDefault);
        }
        private static bool IsDefault(string executablePath)
        {
            var defaultCmd = (string) RegistryHelper.GetValue(Registry.ClassesRoot, @"HTTP\shell\open\command");

            if (!string.IsNullOrWhiteSpace(defaultCmd))
            {
                return defaultCmd.ToLowerInvariant()
                    .Contains(executablePath.ToLowerInvariant());
            }

            return false;
        }
}

Related Tutorials