2014-09-29 29 views
1

我要關閉IE窗口時,URL中包含類似的字符串:眼鏡蛇錯誤Citrix服務器上關閉IE窗口用C#

我有這樣的代碼和它的作品我的本地機器上:

foreach (InternetExplorer explorer in new ShellWindowsClass()) { 

    String url = explorer.LocationURL; 

    if (url.Contains("cobra")) { 
     explorer.Quit(); 
    } 
} 

的IE瀏覽器和該代碼現在Y上的Citrix系統,當使用這種代碼我得到異常:

Retrieving the COM class factory for component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

我現在該怎麼辦?

回答

0

嘗試:

foreach (InternetExplorer ie in new ShellWindows()) { 
      //... 
     } 
+0

請爲您的答案添加一些解釋,說明它的功能以及如何解決問題。這將有助於其他人在未來看到您的答案 – 2014-09-29 10:00:04

+0

我將其更改爲您的答案,但它沒有關閉窗口或標籤。 – Andrija 2014-09-29 10:25:26

+0

新的ShellWindowsClass()或新的ShellWindows()會拋出異常 – Andrija 2014-10-06 09:17:36

0

我搜索,發現new SHDocVw.ShellWindows()不會在Citrix環境中工作。作爲此link

It appears that ShellWindows class (used to enumerate InternetExplorer windows) is hosted by explorer.exe process.

Thus since Citrix in seamless mode does not run explorer.exe

給出所以,你可以用其他的方式像

FindWindowEx method of user32.dll

見上面的鏈接瞭解詳情。

+0

感謝您的建議。 第一個代碼與我使用的相同。目前,當新的ShellWindows()我在Citrix環境中看到異常時(請參閱第一段文字) 您的第二個代碼殺死了完整的IE,我只想關閉帶有包含字符串的url的選項卡。 – Andrija 2014-09-29 14:43:02

+0

沒有第一個代碼不完全相同,我用ShellWindows而不是ShellWindowsClass,並且還有一個額外的FullName檢查。你有沒有試過這段代碼? – prem 2014-09-30 04:49:48

+0

新的ShellWindowsClass()或新的ShellWindows()引發異常 – Andrija 2014-10-06 09:17:19