Creating an Instance of Internet Explorer in C#

I was trying to write a program that opened an instance of Internet Explorer in a separate window, rather than use the Browser control that comes with the .NET platform.

Unfortunately, it proved almost impossible to find any references to the interfaces necessary to do the job.

This is a very simple program that allows the user to type a URL into a textbox, and then open IE directly to that URL.

This only works with IE4 and above.

The heart of the code is exposing the IWebBrowserApp interface. This interface is located in the SHDocVw.dll, which can be found (on Win2K/Xp) in the System32 directory.

The source code is simple:

using SHDocVw;
public void OpenBrowser(string url)
{
object o = null;
SHDocVw.InternetExplorer ie =
new
SHDocVw.InternetExplorerClass();
IWebBrowserApp wb = (IWebBrowserApp) ie;
wb.Visible =
true;
//Do anything else with the window here that you wish
wb.Navigate(url, ref o, ref o, ref o, ref o);
}

I hope this is useful to others.

Up Next
    Ebook Download
    View all
    Learn
    View all