透過 SHDocVw.ShellWindowsClass 列舉系統開啟的 Shell 視窗,篩選 iexplore 進程,讀取 LocationURL 屬性。
using SHDocVw;
using System.Windows.Forms;
ShellWindowsClass shellWindows = new ShellWindowsClass();
foreach (InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
Console.WriteLine(ie.LocationURL);
}
}
需參考 Microsoft Internet Controls (SHDocVw.dll) COM 元件。