How to get and set your own browser as the default browser

Source: Internet
Author: User

Inside. NET, there is a WebBrowser control, which can be used for many purposes, many people use to customize their own browsers, this article talk about how to get the default browser settings, and how to set your browser as the default browser tips.

First look at a small interface graphics, to better understand the use of this feature, the following figure we can see the need to obtain the system's default browser name, and provide the default browser settings.

In fact, these operations are related to the registry, which is stored in the default value of the key Hkey_classes_root\http\shell\open\command,

The name of the default browser is kept in the default value of the Hkey_classes_root\http\shell\open\ddeexec\application.

Basically, we modify these two key values to achieve the default browser settings.

In the above default browser interface, I encapsulate some methods, now published, I hope to be useful to everyone.

private void Frmoptions_load (object sender, EventArgs e)
{
Initdefaultbrowser ();

private void Initdefaultbrowser ()
{
String defaultname = Registryh Elper. Getdefaultbrowername ();
Try
{
String browserpath = Cregex.gettext (DefaultName, "\" (? <ke Y>.*?) \ "", 1);
FileInfo FileInfo = new FileInfo (Browserpath);
String fileName = FileInfo.Name.Replace (Fileinfo.extension, "");
This.lblDefaultName.Text = fileName;             
}
catch (Exception ex)
{
Loghelper.error (ex);

}
private void Btnsetdefault_click (object sender, EventArgs e)
{
Registryhelper.setdefaultbrowser (Application.executablepath);
Messageutil.showtips ("Set default browser Success");
             Initdefaultbrowser ();
}
private void Btnreset_click (object sender, EventArgs e)
{
Regis Tryhelper.resetiedefaultbrowser ();
Messageutil.showtips ("Restore IE succeeded for default browser");
Initdefaultbrowser ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.