C# 从IE处理COM事件

C# 从IE处理COM事件,c#,.net,internet-explorer,com,C#,.net,Internet Explorer,Com,我需要监视客户端PC上的所有IE实例,并在浏览器上导航到某些页面时执行操作,然后再次在浏览器上执行操作,从这些页面中导航或关闭承载这些页面的窗口 我编写了以下代码,将列出所有打开的窗口: private static void ListWindows() { SHDocVw.ShellWindows shellWindows = new ShellWindows(); shellWindows.WindowRegistered += new DShellWindowsEvent

我需要监视客户端PC上的所有IE实例,并在浏览器上导航到某些页面时执行操作,然后再次在浏览器上执行操作,从这些页面中导航或关闭承载这些页面的窗口

我编写了以下代码,将列出所有打开的窗口:

private static void ListWindows()
{
    SHDocVw.ShellWindows shellWindows = new ShellWindows();

    shellWindows.WindowRegistered += new DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);
    foreach (SHDocVw.IWebBrowser2 ie in shellWindows)
    {
        Console.WriteLine("ie.LocationURL: " + ie.LocationURL);
    }
}
部分基于

但如果我要用它的话,我需要每隔一秒钟左右进行一次民意调查,每次都要浏览这个列表

我还发现了一些允许我注册以下事件的代码:

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

        IE.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(IE_BeforeNavigate2);
        IE.OnQuit += new DWebBrowserEvents2_OnQuitEventHandler(IE_OnQuit);
        IE.WindowClosing += new DWebBrowserEvents2_WindowClosingEventHandler(IE_WindowClosing);

但这似乎只适用于我自己打开的窗口(要么就是我做错了什么)。是否有办法为桌面上的任何IE窗口注册事件处理程序?

不清楚您为什么从使用从ShellWindows检索到的IE实例切换到使用新的运算符创建自己的IE实例。@OmarKooheji,您为什么需要轮询,您不能查看
WindowRegistered
事件列表吗?无关,请记住进程外事件处理程序。对于控制台应用程序来说可能不是问题,但仍然是。您的问题似乎非常适合浏览器帮助对象(BHO)。