设置默认浏览器

STT*_*STT 1 .net c#

我正在为 Web 浏览器编写应用程序。就像其他浏览器(Internet Explorer、Google Chrome 等)一样,我需要要求用户将我的应用程序设置为默认浏览器。

有没有办法通过代码设置默认浏览器?

Pat*_*man 5

根据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");
}
Run Code Online (Sandbox Code Playgroud)

这将设置Progid为来自 Internet Explorer 的设置。您应该创建自己的并在Progid此处注册。

另请参阅MSDN 上的完整解释文章。