如何使用每个选项卡的PID获取Internet Explorer选项卡的URL?

我的应用程序触发了具有特定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

它会工作…… 🙂