如何使用C#查找默认的Web浏览器?

有没有办法使用C#找出默认Web浏览器的名称?(Firefox,Google Chrome等)。

你能举个例子给我看看吗?

回答:

您可以在此处查看示例,但主要可以通过以下方式完成:

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浏览器? 的全部内容, 来源链接: utcz.com/qa/420707.html

回到顶部