?
Solved

vb.net how to find all internet explorer sessions and the urls

Posted on 2003-03-02
10
Medium Priority
?
543 Views
Last Modified: 2012-05-04
in vb.Net i need to be able to find how many internet explorer sessions are open and the url each is browsing currently.

thanks for the help
0
Comment
Question by:ocsscott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 1

Accepted Solution

by:
Smashmad earned 400 total points
ID: 8054902
Hi!
put all this in a .bas Module

'----------------------
Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE




Public Sub list()
Call EnumWindows(AddressOf EnumWindowsProc, 0)
End Sub


Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
  Dim slength As Long, buffer As String  ' title bar text length and buffer

  buffer = Space(8)
  slength = GetClassName(hwnd, buffer, 8)
 
  If Left(LCase(buffer), slength) = "ieframe" Then
    Debug.Print gettext(hwnd) ' <------------------------ HERE IS THE TITLE
     
    Call EnumChildWindows(hwnd, AddressOf EnumChildProc, 0)
         
  End If
 
   EnumWindowsProc = 1  ' return value of 1 means continue enumeration
End Function


Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
  Dim slength As Long, buffer As String  ' title bar text length and buffer

  buffer = Space(5)
  slength = GetClassName(hwnd, buffer, 5)
  If Left(LCase(buffer), slength) = "edit" Then
    Debug.Print gettext(hwnd) ' <<<--------------------- HERE IS THE URL
    EnumChildProc = 0
    Exit Function
  End If

  EnumChildProc = 1  ' nonzero return value means continue enumeration
End Function




Function gettext(ByVal win As Long) As String

' Display the title bar text of window Form1 by sending the
' appropriate messages to it.
Dim wintext As String  ' receives the copied text from the target window
Dim slength As Long  ' length of the window text
Dim retval As Long  ' return value of message

' First, determine how much space is necessary for the buffer.
' (1 is added for the terminating null character.)
slength = SendMessage(win, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
' Make enough room in the buffer to receive the text.
wintext = Space(slength)
' Copy the target window's text into the buffer.
retval = SendMessage(win, WM_GETTEXT, ByVal slength, ByVal wintext)
' Remove the terminating null and extra space from the buffer.
wintext = Left(wintext, retval)
' Display the result.
gettext = wintext


End Function







'NOW, CALLING FUNCTION LIST, YOU GET ALL URL AND TITLES
0
 

Author Comment

by:ocsscott
ID: 8057382
this will work in .net with no changes?  I cant test till tonight.  thanks

scott
0
 

Author Comment

by:ocsscott
ID: 8057419
this seems to be for vb6.. can you convert it to vb.net?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:Smashmad
ID: 8058461
I dont know vb.net. I made the code for vb5 or 6. have you test if it works?
0
 
LVL 1

Expert Comment

by:Smashmad
ID: 8058467
it only use APIs, so I think it should work
0
 

Author Comment

by:ocsscott
ID: 8059625
the api's need to be coverted as data types have changes and I think other changes may be needed as well but I havent converted api calls yet.
0
 
LVL 1

Expert Comment

by:Smashmad
ID: 8061820
well, in that case I cant help you... I cant get VB.net.. im trying..
0
 

Author Comment

by:ocsscott
ID: 8065406
ill try my hand at it tonight and post if if I get it working
0
 

Author Comment

by:ocsscott
ID: 8083101
I posted the code in the .net section it needs delegates whatever they are.  I'll post the code once converted
0
 

Author Comment

by:ocsscott
ID: 8089376
you are awesome.  great code.  here is the .net converted code


Option Strict Off
Option Explicit On

Imports System.Runtime.InteropServices
Imports System.Text


Module Module1
    '----------------------

    'Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
    Public Delegate Function EnumWindowsCallback(ByVal hWnd As Integer, ByVal lParam As Integer) As Integer
    Public Declare Function EnumWindows Lib "user32.dll" Alias "EnumWindows" (ByVal callback As EnumWindowsCallback, ByVal lParam As Integer) As Integer

    'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1016"'
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer


    Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
    Public Delegate Function EnumChildWindowsCallback(ByVal hWnd As Integer, ByVal lParam As Integer) As Integer
    Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Integer, ByVal lpEnumFunc As EnumChildWindowsCallback, ByVal lParam As Integer) As Integer
      
      Const WM_GETTEXT As Short = &HDs
      Const WM_GETTEXTLENGTH As Short = &HEs
      Public intNumSessions As Short
      
      Public Sub list()
            
            'UPGRADE_WARNING: Add a delegate for AddressOf EnumWindowsProc Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1048"'
        Call EnumWindows(AddressOf EnumWindowsProc, 0)
            
            Form1.DefInstance.Label1.Text = intNumSessions & "  IE Sessions Open"
            
      End Sub



      Public Function EnumWindowsProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
            
            Dim slength As Integer
            Dim buffer As String ' title bar text length and buffer
            
            buffer = Space(8)
            slength = GetClassName(hwnd, buffer, 8)
            
            If Left(LCase(buffer), slength) = "ieframe" Then
                  
            'Form1.Text1.Text = Form1.Text1.Text & vbCrLf & gettext(hwnd)   ' <------------------------ HERE IS THE TITLE
                  
                  'UPGRADE_WARNING: Add a delegate for AddressOf EnumChildProc Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1048"'
                  Call EnumChildWindows(hwnd, AddressOf EnumChildProc, 0)
                  
                  intNumSessions = intNumSessions + 1
                  
            End If
            
            EnumWindowsProc = 1 ' return value of 1 means continue enumeration
            
      End Function
      
      Public Function EnumChildProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
            
            Dim slength As Integer
            Dim buffer As String ' title bar text length and buffer
            
            buffer = Space(5)
            slength = GetClassName(hwnd, buffer, 5)
            If Left(LCase(buffer), slength) = "edit" Then
                  
            ' <<<--------------------- HERE IS THE URL
                  Form1.DefInstance.Text1.Text = Form1.DefInstance.Text1.Text & vbCrLf & vbCrLf & gettext(hwnd)
                  
                  EnumChildProc = 0
            Exit Function

            End If
            
            EnumChildProc = 1 ' nonzero return value means continue enumeration
            
      End Function
      
      Function gettext(ByVal win As Integer) As String
            
            ' Display the title bar text of window Form1 by sending the
            ' appropriate messages to it.
            
        Dim wintext As String  ' receives the copied text from the target window
            Dim slength As Integer ' length of the window text
        Dim retval As Integer  ' return value of message
            
            ' First, determine how much space is necessary for the buffer.
            ' (1 is added for the terminating null character.)
            slength = SendMessage(win, WM_GETTEXTLENGTH, CInt(0), CInt(0)) + 1

        wintext = Space(slength)  ' Make enough room in the buffer to receive the text.

        retval = SendMessage(win, WM_GETTEXT, slength, wintext) ' Copy the target window's text into the buffer.

        wintext = Left(wintext, retval)  ' Remove the terminating null and extra space from the buffer.

        gettext = wintext  ' Display the result.
            
      End Function
End Module
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question