參考 -> com -> Microsoft Internet Control
成功后如下圖:

代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
bool hasCurrentUrl = false;
foreach (SHDocVw.InternetExplorer browser in shellWindows)
{
if (string.IsNullOrEmpty(browser.FullName))
{
continue;
}
string filename = Path.GetFileNameWithoutExtension(browser.FullName).ToLower();
if (filename.Equals("iexplore") && browser.LocationURL.Contains("https://www.baidu.com"))
{
hasCurrentUrl = true;
Console.WriteLine("GetFileName('{0}') returns '{1}'", filename, hasCurrentUrl);
Console.ReadLine();
break;
}
}
if (hasCurrentUrl == false)
{
Console.WriteLine("未找到相應網址");
Console.ReadLine();
}
}
}
}
可以手工打開IE瀏覽器 并打開https://www.baidu.com測驗
uj5u.com熱心網友回復:
ie 沒有這種功能uj5u.com熱心網友回復:
SHDocVw.ShellWindows()是COM時代的產物,包括資源管理器和IE視窗。遍歷它確實可以得到IE打開的視窗。uj5u.com熱心網友回復:
有時網頁會自動跳轉,Url會變。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/71699.html
標籤:C#
上一篇:c#報表
