如何唯一标识会话0中运行的Internet Explorer窗口? [英] How to uniquely identify an internet explorer window running in session 0?

查看:270
本文介绍了如何唯一标识会话0中运行的Internet Explorer窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建 WCF Web服务的automatea 的Internet Explorer 。有需要访问的Internet Explorer 的同一实例的多个Web服务调用。然而,由于 WCF 服务在 IIS 所有Web服务调用托管在会话0被执行现在访问的的Internet Explorer 我用 SHDocVw.InternetExplorer.HWND 属性,它返回的窗口句柄<同一实例code>的Internet Explorer 实例。在下面的代码时,作为 A WCF 服务执行IIS 7 的窗口句柄始终返回0,因为会话0隔离。另外,我不能够通过所有打开的 IE 窗钩回同一 IE 实例或循环。我可以枚举进程列表中,找到每个 IE 窗口会话0开放进程ID,但不能投了的System.Diagnostics.Process SHDocVw.InternetExplorer 对象



下面是我的代码:

 公众诠释GetWhd()
{
InternetExplorer的IE =新的InternetExplorer();
ie.Visible = TRUE;
返回ie.HWND;
}

公众诠释SetWhd(字符串WHD)
{
INT WH = Int32.Parse(WHD);
的InternetExplorer即= NULL;
ShellWindows S =新ShellWindows();
的foreach(SHDocVw.InternetExplorer IE1在S)
{

{
如果(ie1.HWND == WH)
{
即= IE1;
中断;
}
}
抓{返回2; }
}
如果(即!= NULL){ie.Navigate(www.google.com);返回1; }
返回0;
}



任何帮助将非常感激。


< DIV CLASS =h2_lin>解决方案

这是很难在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更改设置对象
开始 - >运行 - > comexp.msc



打开组件服务 - >电脑 - >我的电脑 - > DCOM配置
找到Internet Explorer的条目,右键单击 - >属性 - >身份标签 - >选择交互式用户



另外,如果你的使用情况允许,举办一个WPF应用程序内的WCF应用程序,如果需要,你可以去至于托管应用程序内部的Internet Explorer窗口,这将给你更多的控制。浏览器控件API似乎在你之前,将它转换为适当的类型第一(智能影音感智慧)的限制。如果需要,我可以张贴此



编辑:同时看一看的 http://support.microsoft.com/kb/555134


I am creating WCF web services that automatea internet explorer. There are multiple web service calls that need to access the same instance of Internet Explorer. However, since the WCF services are hosted on IIS all the calls to the web service are executed in session 0. Now to access the same instance of Internet Explorer I use SHDocVw.InternetExplorer.HWND property which returns the window handle of an Internet Explorer instance. In below code when executed as a WCF service on IIS 7 the window handles always return 0 due to session 0 isolation. Also, I am not able to hook back to the same IE instance or loop through all the open IE windows. I can enumerate the process list and find process ids for each IE window open in session 0, but cannot cast a System.Diagnostics.Process to SHDocVw.InternetExplorer object.

Below is my code:

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;
}

Any help will be much appreciated.

解决方案

It's difficult to fully escape isolation in IIS7, but here's what I did in a similar scenario: In IIS, go to Advanced Settings on your application pool, and set it to run as a windows user. Make sure you logged in with that user at least once (.net creates some undocumented folders). Set Load User Profile to True

In my case I was automating MS Office, so I had the following 2 additional steps (first might be applicable): C:\Windows\System32\config\systemprofile create Desktop folder, give it write permissions C:\Windows\System32\config\systemprofile\AppData\Roaming\Microsoft\Templates make sure Normal.dotm is there and it has write permissions

Next, change settings on the DCOM objects Start -> run -> comexp.msc

Open Component Services -> Computers -> My Computer -> DCOM Config locate the Internet Explorer entry, Right-click -> Properties -> Identity Tab -> select The interactive user

Alternatively, if your use case allows, host the WCF application inside a WPF application, and if needed, you can go as far as hosting an Internet Explorer window inside the app, which will give you more control. The browser control API seems limited at first (intelli-sense wise) until you cast it to the appropriate type. I can post this if needed.

EDIT: Also take a look at http://support.microsoft.com/kb/555134

这篇关于如何唯一标识会话0中运行的Internet Explorer窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆