using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using SHDocVw;
using mshtml;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ShellWindows shellWindows = new ShellWindowsClass();
foreach (InternetExplorer ie in shellWindows)
{
string fileName = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (fileName.Equals("iexplore"))
{
Console.WriteLine("Web Site: {0}", ie.LocationURL);
IHTMLDocument2 htmlDoc = ie.Document as IHTMLDocument2;
string snippet = (htmlDoc != null) ? htmlDoc.body.outerHtml.Substring(0, 40) : "***Failed***";
Console.WriteLine("Document Snippet: {0}", snippet);
Console.WriteLine();
}
}
}
}
}
ShellWindows、InternetExplorer。IHTMLDocument2。專案需勾選「Embed Interop Types」或部署時包含 PIA。程式列舉所有殼層視窗,篩選 iexplore 進程,輸出網址與 HTML 片段。