I have a C# project that open urls in an IE Browser using Interop.SHDocVw.
The code is using a single instance of a InternetExplorerClass object and navigates to different urls. These urls are all in the Intranet zone.
The code works fine on WIN7 but on WIN10 there is a problem. The IE browser opens the url correctly in the first time but when I try to use it in the second time using the navigate or navigate2 methods I get the following error:
System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) at SHDocVw.InternetExplorerClass.Navigate(String URL, Object& Flags, Object& TargetFrameName, Object& PostData, Object& Headers)
I tried to run the host application "as administrator" and then it worked fine. Also when I navigate manually in the IE window to a url in internet zone there is no problem, but when navigating manually to a different intranet url and trying to run the code in the second time, the error is being thrown again.
The code:
public static void IEOpenOnURL(string url) { object o = null; bool newBrowser =false;
//check if window is already opened
if(webBrowser==null)
{
newBrowser = true;
}
else
{
try
{
//Cannot navigate in browser with an open modal dialog
if(webBrowser.Busy)
{
MessageBox.Show("הדפדפן תפוס - סגור את החלונות הקופצים מתוך הדפדפן הפתוח");
return;
}
}
//an error is thrown when the browser was closed by user
catch(Exception)
{
newBrowser = true;
}
}
if(newBrowser)
{
//create new instance of the browser
InternetExplorer explorer = new InternetExplorerClass();
webBrowser = (IWebBrowser2)explorer;
}
webBrowser.Visible = true;
//webBrowser.Navigate(url, ref o, ref o, ref o, ref o);
webBrowser.Navigate2(url, ref o, ref o, ref o, ref o);
//Set focus
SetForegroundWindow((IntPtr)webBrowser.HWND);
//If browser is minimized - show it
ShowWindow((IntPtr)webBrowser.HWND,9);
}
}
I am not going to say I know the exact answer offhand. But I would say you normally are supposed to initialize Internet Explorer via the interface instead of the class. I have run into errors when I have tried to initialize the class directly.
Try this :
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
IE.Visible = true;
User contributions licensed under CC BY-SA 3.0