2016-06-15 37 views
0

我有一個C#項目,它在IE瀏覽器中使用Interop.SHDocVw打開URL。操作中止WIN10中使用SHDocVw導航2進行導航時出現異常,例如

該代碼使用InternetExplorerClass對象的單個實例並導航到不同的URL。這些網址全部位於Intranet區域內。

該代碼工作正常WIN7WIN10有一個問題。 IE瀏覽器正確打開的URL在第一時間,但是當我嘗試使用導航或navigate2方法我收到以下錯誤使用它在第二次:

System.Runtime.InteropServices.COMException(0x80004004) :操作中止(從HRESULT異常:0x80004004(E_ABORT)) 在SHDocVw.InternetExplorerClass.Navigate(字符串的URL,對象&旗,對象& TargetFrameName,對象& POSTDATA,對象&頭)

我試着運行主機應用程序「以管理員身份」,然後它工作正常。 另外,當我在IE窗口中手動導航到internet區域的手動導航時,沒有任何問題,但是當手動導航到不同的intranet url並試圖在第二次運行代碼時,錯誤正在拋出再次。

代碼

公共靜態無效IEOpenOnURL(字符串URL) { 對象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); 
    } 
} 
+0

嗨Yosi,我們再遇到同樣的問題。你有沒有找到解決這個問題的方法? – FreddieGericke

回答

0

我不打算說我知道準確的答案。但我會說你通常應該通過界面而不是類來初始化Internet Explorer。當我嘗試直接初始化類時遇到了錯誤。

試試這個:

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer(); 
    IE.Visible = true;