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 ();
}