如何使用C#找到默认Web浏览器? [英] How to find default web browser using C#?

查看:253
本文介绍了如何使用C#找到默认Web浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,我可以找出使用C#我的默认网页浏览器的名字吗?
(火狐,谷歌Chrome等)

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?

推荐答案

您可以看看<一个href=\"http://www.dreamin$c$c.net/forums/blog/143/entry-2054-get-default-browser-more-in-c#/\">here为一个例子,但主要是它可以这样做:

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;

    try
    {
        //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());
    }
    finally
    {
        //check and see if the key is still open, if so
        //then close it
        if (regKey != null)
            regKey.Close();
    }
    //return the value
    return name;

}

这篇关于如何使用C#找到默认Web浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆