Visual Studio 任意版本建立主控台應用程式 → 專案右鍵「加入參考」→ COM 標籤 → 勾選:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string fileName = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (fileName.Equals("iexplore"))
{
Console.WriteLine("Web Site: {0}", ie.LocationURL);
mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;
Console.WriteLine("Document Snippet: {0}",
htmlDoc != null ? htmlDoc.body.outerHtml.Substring(0, 40) : "***Failed***");
Console.WriteLine();
}
}

此法適用於自動化測試、網頁內容擷取、單一登入 (SSO) 輔助等場景。注意:現代 Edge/Chrome 需用 WebDriver (Selenium) 或 CDP 協議。