您可以在C#程序中使用COM/OLE連接到Internet Explorer的正在運行的實例嗎?如何使用c#連接到Internet Explorer的打開窗口?
理想情況下,我想查找在IE中打開的所有網頁的網址。
您可以在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.謝謝!
ShellWindows可能不適用於Vista +上的低權限IE窗口。 – 2010-07-20 15:29:47
我得到了錯誤「Interop類型不能嵌入。使用適當的接口」,所以我將第一行從「new SHDocVw.ShellWindowsClass()」更改爲「new SHDocVw.ShellWindows()」,然後能夠循環IE的開放實例。 – 2015-11-13 19:00:43
Manisha Mehta在http://www.codeproject.com/KB/cs/runninginstanceie.aspx上顯示如何操作。
webbrowser怎麼樣? – Luiscencio 2010-07-19 23:08:22
在這種情況下,webbrowser控件不起作用,因爲我不希望程序負責顯示網頁,只是想知道在ie的打開實例中顯示什麼。 – Evan 2010-07-19 23:30:38