Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#
Article

Internet Explorer Activity Monitor

Rate me:
Please Sign up or sign in to vote.
3.64/5 (8 votes)
29 Oct 2005CPOL 132.5K   2.7K   49   31
The Internet Activity Monitor captures what you are doing on Internet Explorer like opening a browser, requesting a Website and closing the browser.
Sample image

Introduction

This application is a simple but useful one. I used this application in a Windows Service which monitors the activity of the browser and the person logged-in at that time.

Adding Reference

Sample Image - IE_Activity_Monitor.jpg

Add a reference in your project to SHDocVw.dll. This is a COM component named Microsoft Internet Controls. It contains the definitions of the InternetExplorer and ShellWindows classes.

About the Code

The code can be divided into three parts:

  1. Browser Open Activity
  2. Browser Navigation Activity
  3. Browser Close Activity

Following are the event handlers that are fired at their respective events:

C#
// THIS EVENT IS FIRED WHEN A NEW BROWSER IS OPENED
        private void shellWindows_WindowRegistered(int z)
        {            
            string filnam;        
            
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filnam = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
    
                if (filnam.Equals("iexplore"))
                {
                    browser = ie;    
                        
                    bool check=true;

                    for (int i=0; i<Current_IE_Handles.Count; i++)
                    {
                        if (Current_IE_Handles[i].ToString()==browser.HWND.ToString())
                        {
                            check=false;
                        }
                    }
                        
                    if (check==true)
                    {
                        Current_IE_Handles.Add(browser.HWND.ToString());
                        this.listBox1.Items.Add("Browser Open : Handle
					( "+browser.HWND.ToString()+" )");
                        browser.BeforeNavigate2+=
			new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler
			(browser_BeforeNavigate2);
                    }                        
                }
            }            
        }

When you type something like www.codeproject.com, this event is fired and here you can capture all the information about the Internet Explorer Navigation.

C#
// THIS EVENT IS FIRED WHEN THE BROWSER IS JUST ABOUT TO NAVIGATE TO A WEBSITE
        private void browser_BeforeNavigate2(object a,ref object b,
		ref object c,ref object d,ref object e,ref object f,ref bool g)
        {
            this.listBox1.Items.Add(browser.HWND.ToString()+ " : "+b.ToString());
        }
C#
// THIS EVENT IS FIRED WHEN A NEW BROWSER IS CLOSED
        private void shellWindows_WindowRevoked(int z)        
        {            
            string filnam;
            ArrayList Closed_IE=new ArrayList();
              
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filnam = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
    
                if (filnam.Equals("iexplore"))
                {
                    Closed_IE.Add(ie.HWND.ToString());
                }
            }    
        
            for (int i=0; i<this.Current_IE_Handles.Count; i++)
            {
                bool check=false;

                for (int j=0; j<Closed_IE.Count; j++)
                {
                    if (Convert.ToInt32(this.Current_IE_Handles[i])==
			Convert.ToInt32(Closed_IE[j]))
                        check=true;
                }

                if (check==false)
                {
                    this.listBox1.Items.Add("Browser Closed : Handle
			( "+this.Current_IE_Handles[i].ToString()+" )");
                    this.Current_IE_Handles.RemoveAt(i);
                    break;
                }
            }
        } 

Currently this application captures the activity of the Internet Explorer. A new and improved version will be posted shortly that can monitor the activity of user defined browsers.

Initial Work

I carried forward the work done by Steven M. Cohn. Check out his post at this link.

History

  • 29th October, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Pakistan Pakistan
Ali Raza Shaikh did his BS (CS) from FAST-NUCES, Karachi Campus. He is also a Microsoft Certified Application Developer. He have a great passion for programming and all the programming related stuff. He can be reached at alirazashaikh.blogspot.com

Comments and Discussions

 
GeneralHTTP monitor Pin
Globalization15-Oct-08 6:49
Globalization15-Oct-08 6:49 
GeneralException occur while code placed in a window service Pin
Rizwan Riaz28-May-08 2:47
Rizwan Riaz28-May-08 2:47 
GeneralRe: Exception occur while code placed in a window service Pin
Tejal Bhavsar19-Jun-08 0:00
Tejal Bhavsar19-Jun-08 0:00 
QuestionIE 7 Tabbing, How can you make this work with tabs?? Pin
thephatp23-Mar-08 13:52
thephatp23-Mar-08 13:52 
AnswerRe: IE 7 Tabbing, How can you make this work with tabs?? Pin
Rizwan Riaz21-Jun-08 0:17
Rizwan Riaz21-Jun-08 0:17 
QuestionWindows Service Pin
F.Granata20-Dec-07 21:07
sussF.Granata20-Dec-07 21:07 
GeneralMonitor all application Pin
parvu20043-Nov-07 1:39
parvu20043-Nov-07 1:39 
QuestionInternet Explorer 7 Pin
fredamaral22-May-07 9:26
fredamaral22-May-07 9:26 
QuestionIE Protected Mode on Vista Pin
Pappu5star2-Apr-07 0:49
Pappu5star2-Apr-07 0:49 
GeneralComparing this with Joe Bergeron's Pin
Fresh Mexican Food Fan21-Mar-07 8:19
Fresh Mexican Food Fan21-Mar-07 8:19 
GeneralPopup Pin
Tadas Danielius10-Nov-06 23:54
Tadas Danielius10-Nov-06 23:54 
Generalother browsers.. Pin
AAndrews22-Jul-06 8:37
AAndrews22-Jul-06 8:37 
Generalstops in some conditions Pin
RupeshV15-May-06 18:16
RupeshV15-May-06 18:16 
GeneralCannot Run As a Windows Service Pin
dnan25-Apr-06 20:41
dnan25-Apr-06 20:41 
GeneralRe: Cannot Run As a Windows Service Pin
scippyone18-May-07 7:36
scippyone18-May-07 7:36 
Generalsetting the code into a dll Pin
RupeshV10-Apr-06 20:26
RupeshV10-Apr-06 20:26 
Generalnice Pin
punkcpp29-Mar-06 19:17
punkcpp29-Mar-06 19:17 
GeneralRe: nice Pin
punkcpp29-Mar-06 19:19
punkcpp29-Mar-06 19:19 
Questioncan you make it better Pin
pennamaraju18-Jan-06 17:38
pennamaraju18-Jan-06 17:38 
AnswerRe: can you make it better Pin
Ali Raza Shaikh28-Jan-06 22:27
Ali Raza Shaikh28-Jan-06 22:27 
GeneralRe: can you make it better Pin
Jack987622-Feb-10 2:52
Jack987622-Feb-10 2:52 
GeneralBUG whan open more windows Pin
EmailSolidale22-Nov-05 22:54
EmailSolidale22-Nov-05 22:54 
GeneralRe: BUG whan open more windows Pin
Ali Raza Shaikh28-Jan-06 22:30
Ali Raza Shaikh28-Jan-06 22:30 
GeneralRe: BUG whan open more windows Pin
Tadas Danielius11-Nov-06 2:59
Tadas Danielius11-Nov-06 2:59 
GeneralRe: BUG whan open more windows Pin
scippyone6-May-07 5:22
scippyone6-May-07 5:22 
This is my vb solution when more than one window of IE is opened:

Private Sub shellWindows_WindowRegistered(ByVal num1 As Integer)<br />
    Dim explorer1 As SHDocVw.InternetExplorer<br />
    Dim browser As SHDocVw.InternetExplorer = Nothing<br />
    For Each explorer1 In shellWindows<br />
        browser = explorer1<br />
    Next<br />
    Dim id As String<br />
    id = browser.HWND.ToString<br />
    Dim conta_id_shell As Integer = 0<br />
    For Each explorer1 In shellWindows<br />
        If id = explorer1.HWND.ToString Then<br />
            conta_id_shell = conta_id_shell + 1<br />
        End If<br />
    Next<br />
    Dim conta_id_array As Integer = 0<br />
    Dim num2 As Integer<br />
    For num2 = 0 To Me.Current_IE_Handles.Count - 1<br />
        If Me.Current_IE_Handles.Item(num2).ToString = id Then<br />
            conta_id_array = conta_id_array + 1<br />
        End If<br />
    Next num2<br />
    If conta_id_shell > conta_id_array Then<br />
        Me.Current_IE_Handles.Add(id)<br />
        AddHandler browser.BeforeNavigate2, AddressOf browser_BeforeNavigate2<br />
    End If<br />
End Sub

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.