[英]How to get the URL of the Internet explorer tabs with PID of each tab?
我的應用程序觸發了具有特定URL的Web瀏覽器。 我的程序結束后,我想關閉我打開的網頁/標簽..
通過調用帶參數a的EXE文件。 流程名稱b。 URL中存在的字符串
詳細問題如何從Java / C ++中殺死firefox子進程/選項卡
我用C#方法......
我能夠找到所有選項卡的進程ID ..
foreach (Process theprocess in processlist) {
if (theprocess.ProcessName == "iexplore") {
Console.WriteLine("Process: {0}\tID: {1}\tWindow name: {2}",
theprocess.ProcessName, theprocess.Id, theprocess.MainWindowTitle
);
}
}
目前我只能獲得進程的Window Title ....而在IE8中只有一個主進程的窗口標題可見..
如果我有每個選項卡的pid,如何找到選項卡的URL ...並僅殺死該選項卡?
當我試圖從地址欄的句柄獲取url(文本)時,我得到了Access的拒絕幫助
使用SHDocVw; 。 。
foreach(InternetExplorer ieInst in new ShellWindowsClass())Console.WriteLine(ieInst.LocationURL);
在IE7及更高版本中,下面的代碼將僅刪除其URL中具有匹配字符串的選項卡。
foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindows())
{
String url = ieInst.LocationURL;
if (url.Contains("google"))
{
ieInst.Quit();
}
}
要聚焦特定選項卡,代碼為:
foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindows())
{
String url = ieInst.LocationURL;
if (url.Contains("google"))
{
int val = ieInst.HWND;
IntPtr hwnd = new IntPtr(val);
ShowWindow(hwnd, SW_MAXIMISE);
SetForegroundWindow(hwnd);
}
}
有一種方法可以獲取每個IExplorer實例的URL!
向項目添加引用“ Microsoft Internet Controls ”。
這段代碼是
**foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
{
System.Console.WriteLine(ieInst.LocationURL);
}**
生成exe和Interop.SHDocVw.dll
它會工作...... :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.