【发布时间】:2014-08-11 12:38:18
【问题描述】:
我正在为 Web 浏览器编写应用程序。就像其他浏览器(Internet Explorer、Google Chrome 等)一样,我需要要求用户将我的应用程序设置为默认浏览器。
有没有办法通过代码设置默认浏览器?
【问题讨论】:
我正在为 Web 浏览器编写应用程序。就像其他浏览器(Internet Explorer、Google Chrome 等)一样,我需要要求用户将我的应用程序设置为默认浏览器。
有没有办法通过代码设置默认浏览器?
【问题讨论】:
根据MSDN 上的这个答案,您需要更改注册表项:
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", true);
string browser = regkey.GetValue("Progid").ToString();
if (browser != "IE.HTTP")
{
regkey.SetValue("Progid", "IE.HTTP");
}
这会将Progid 设置为Internet Explorer 中的Progid。您应该创建一个自己的帐户并在此处注册您的Progid。
另见此完整解释article on MSDN。