如何使用c#连接到Internet Explorer的打开窗口?
问题描述:
您可以在C#程序中使用COM/OLE连接到Internet Explorer的正在运行的实例吗?如何使用c#连接到Internet Explorer的打开窗口?
理想情况下,我想查找在IE中打开的所有网页的网址。
答
我找到了答案here和代码摘录:
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.谢谢!
+0
ShellWindows可能不适用于Vista +上的低权限IE窗口。 – 2010-07-20 15:29:47
+0
我得到了错误“Interop类型不能嵌入。使用适当的接口”,所以我将第一行从“new SHDocVw.ShellWindowsClass()”更改为“new SHDocVw.ShellWindows()”,然后能够循环IE的开放实例。 – 2015-11-13 19:00:43
webbrowser怎么样? – Luiscencio 2010-07-19 23:08:22
在这种情况下,webbrowser控件不起作用,因为我不希望程序负责显示网页,只是想知道在ie的打开实例中显示什么。 – Evan 2010-07-19 23:30:38