簡體   English   中英

如何唯一標識在會話0中運行的Internet Explorer窗口?

[英]How to uniquely identify an internet explorer window running in session 0?

我正在創建自動化internet explorer WCF web services 有多個Web服務調用需要訪問同一個Internet Explorer實例。 但是,由於WCF服務托管在IIS所有對Web服務的調用都在會話0中執行。現在要訪問Internet Explorer的同一實例,我使用SHDocVw.InternetExplorer.HWND屬性返回Internet Explorer實例的窗口句柄。 在下面的代碼中,當作為IIS 7上的WCF服務執行時,由於會話0隔離,窗口句柄始終返回0。 此外,我無法掛鈎到相同的IE實例或循環所有打開的IE窗口。 我可以枚舉進程列表並查找在會話0中打開的每個IE窗口的進程ID,但不能將System.Diagnostics.ProcessSHDocVw.InternetExplorer對象。

以下是我的代碼:

public int GetWhd()
{
    InternetExplorer ie = new InternetExplorer();
    ie.Visible = true;
    return ie.HWND;
}

public int SetWhd(string whd)
{
    int wh = Int32.Parse(whd);
    InternetExplorer ie = null;
    ShellWindows s = new ShellWindows();
    foreach (SHDocVw.InternetExplorer ie1 in s)
    {
    try
    {
            if (ie1.HWND == wh)
            {
                    ie = ie1;
                    break;
            }
    }
    catch { return 2; }
    }
    if (ie != null) { ie.Navigate("www.google.com"); return 1; }
    return 0;
}

任何幫助都感激不盡。

在IIS7中完全逃避隔離是很困難的,但這是我在類似場景中所做的:在IIS中,轉到應用程序池上的“高級設置”,並將其設置為以Windows用戶身份運行。 確保您至少使用該用戶登錄一次(.net創建一些未記錄的文件夾)。 將加載用戶配置文件設置為True

在我的情況下,我是自動化MS Office,所以我有以下2個額外的步驟(第一個可能適用):C:\\ Windows \\ System32 \\ config \\ systemprofile創建桌面文件夾,給它寫權限C:\\ Windows \\ System32 \\ config \\ systemprofile \\ AppData \\ Roaming \\ Microsoft \\ Templates確保Normal.dotm存在並且具有寫入權限

接下來,更改DCOM對象上的設置Start -> run -> comexp.msc

打開Component Services -> Computers -> My Computer -> DCOM Config找到Internet Explorer條目, Right-click -> Properties -> Identity Tab -> select The interactive user

或者,如果您的用例允許,在WPF應用程序中托管WCF應用程序,並且如果需要,您可以在應用程序內部托管Internet Explorer窗口,這將為您提供更多控制。 瀏覽器控件API最初似乎是有限的(智能方面),直到您將其轉換為適當的類型。 如果需要我可以發布。

編輯:另請參閱http://support.microsoft.com/kb/555134

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM