如何使用c#连接到Internet Explorer的打开窗口?

你可以在C#程序中使用COM / OLE连接到正在运行的Internet Explorer实例吗?

理想情况下,我想找到在IE中打开的所有网页的url。

我在这里找到答案,代码摘录如下:

public class Form1 : System.Windows.Forms.Form { static private SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); public Form1() { InitializeComponent(); foreach(SHDocVw.InternetExplorer ie in shellWindows) { MessageBox.Show("ie.Location:" + ie.LocationURL); ie.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.ie_BeforeNavigate2); } } public void ie_BeforeNavigate2(object pDisp , ref object url, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) { MessageBox.Show("event received!"); } } 

任何人都知道该网页上的代码是否也适用于IE 6? 我在7上测试了它。谢谢!

Manisha Mehta在http://www.codeproject.com/KB/cs/runninginstanceie.aspx上显示如何执行此操作。