如何获得与每个选项卡的PID Internet浏览器选项卡的网址是什么? [英] How to get the URL of the Internet explorer tabs with PID of each tab?

查看:621
本文介绍了如何获得与每个选项卡的PID Internet浏览器选项卡的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的应用程序触发特定URL的Web浏览器。
我的程序结束后,我要关闭网页/我已经打开的标签。

I have my application which triggers Web Browser with specific URL . After my program ends i want to close the web pages/tabs which i have opened..

通过调用一个带参数的EXE文件。进程名湾字符串出现在URL

By calling an EXE file with parameters a. Process Name b. String present in the URL

详细的问题
如何从Java / C ++

我用C#的方式。 ..

I used C# approach ...

我能找到的所有选项卡。

I am able to find the process ID of all the tabs..

foreach (Process theprocess in processlist) {
    if (theprocess.ProcessName == "iexplore") {
        Console.WriteLine("Process: {0}\tID: {1}\tWindow name: {2}",
            theprocess.ProcessName, theprocess.Id, theprocess.MainWindowTitle
        );
    }
}

目前我能得到这个过程的唯一窗口标题。 ...在IE8只有一个主进程窗口标题是可见的。

Currently i can get only Window Title of the process....and in IE8 only one window title of main process is visible..

我提供每个有标签的PID,如何找到该选项卡的URL。 ..和杀只是标签?

Provided i have the pids of each tabs,How to find the URL of the tab ...and kill only that tab ??

我从
访问被拒绝 - 试图从地址栏的句柄的URL(文本)

使用SHDOCVW;

using SHDocVw; . .

的foreach(InternetExplorer的ieInst新ShellWindowsClass())
Console.WriteLine(ieInst.LocationURL);

foreach (InternetExplorer ieInst in new ShellWindowsClass()) Console.WriteLine(ieInst.LocationURL);

推荐答案

在IE7及更高版本,下面的代码将只杀已经匹配在URL字符串的标签。

In IE7 and later versions, below code will kill only the tab which has matching string in its URL.

   foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
    {
        String url = ieInst.LocationURL;
        if (url.Contains("google"))
        {

            ieInst.Quit();

        }

要聚焦于特定的标签代码:

To focus a specific tab the code is :

   foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
    {
        String url = ieInst.LocationURL;
        if (url.Contains("google"))
        {
            int val = ieInst.HWND;
            IntPtr hwnd = new IntPtr(val);
            ShowWindow(hwnd, SW_MAXIMISE);
            SetForegroundWindow(hwnd);
        }

这篇关于如何获得与每个选项卡的PID Internet浏览器选项卡的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆