Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the URL of the Internet explorer tabs with PID of each tab?

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..

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

Detailed problem How to kill firefox child process/tab from Java/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
        );
    }
}

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

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

I got this help from Access is denied - when trying to get the url (text) from address bar's handle

using SHDocVw; . .

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

like image 812
Shaik Md Avatar asked Dec 09 '11 12:12

Shaik Md


1 Answers

There is a way get the URL of each IExplorer instance !!

Add a reference "Microsoft Internet Controls" to the project.

The piece of code is

**foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
        {
            System.Console.WriteLine(ieInst.LocationURL);
        }**

Generate the exe and Interop.SHDocVw.dll

It will work ...:)

like image 126
Shaik Md Avatar answered Nov 09 '22 20:11

Shaik Md