C# 获取默认浏览器

USBKey的程序中,客户需求插入后开打默认浏览器。网上搜索了下。发现都有点问题。

最后返璞归真,使用注册表监视工具发现 \SOFTWARE\Clients\StartMenuInternet\ 记录了默认浏览器名字

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\默认浏览器名字\shell\open\command] 记录了物理路径。

        /// <summary>
        /// 获取默认浏览器的路径
        /// </summary>
        /// <returns></returns>
        public String GetDefaultWebBrowserFilePath()
        {
            string _BrowserKey1 = @"Software\Clients\StartmenuInternet\";
            string _BrowserKey2 = @"\shell\open\command";

            RegistryKey _RegistryKey = Registry.CurrentUser.OpenSubKey(_BrowserKey1, false);
            if (_RegistryKey == null)
                _RegistryKey = Registry.LocalMachine.OpenSubKey(_BrowserKey1, false);
            String _Result = _RegistryKey.GetValue("").ToString();
            _RegistryKey.Close();

            _RegistryKey = Registry.LocalMachine.OpenSubKey(_BrowserKey1 + _Result + _BrowserKey2);
            _Result = _RegistryKey.GetValue("").ToString();
            _RegistryKey.Close();

            if (_Result.Contains("\""))
            {
                _Result = _Result.TrimStart('"');
                _Result = _Result.Substring(0, _Result.IndexOf('"'));
            }
            return _Result;
        }

 

 

posted @ 2012-05-22 14:51    阅读(1731)  评论(0)    收藏  举报