Reputation: 3207
Does anybody know how I can get the URL of any open IE processes on a computer? I don't need to manipulate the IE instance at all -- just get information about the page that's currently loaded.
Thanks!
Upvotes: 3
Views: 2751
Reputation: 100547
Start IE yourself through automation (i.e var oIE = WScript.CreateObject("InternetExplorer.Application", "IE_");
) and listen to NavigateComplete2
.
Peek inot ROT (running objects table) - I think IE documents should show up there - Win32/COM - http://msdn.microsoft.com/en-us/library/ms684004(VS.85).aspx
Just find all IE windows and take text from address well (see MusiGenesis answer for that).
Upvotes: 0
Reputation: 75296
This appears to be one way of doing it (code is Visual Basic, sorry, but it shows the principle):
Private Declare Function GETWINDOWTEXT Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Const WM_GETTEXT As Short = &HDS
Private Const WM_GETTEXTLENGTH As Short = &HES
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hwnd As Integer = FindWindowEx(0, 0, "IEFrame", vbNullString)
If Not hwnd = 0 Then
SetForegroundWindow(hwnd)
Dim Worker As Integer = FindWindowEx(hwnd, 0, "WorkerW", vbNullString)
Dim ToolBar As Integer = FindWindowEx(Worker, 0, "ReBarWindow32", vbNullString)
Dim ComboBoxEx As Integer = FindWindowEx(ToolBar, 0, "ComboBoxEx32", vbNullString)
Dim txtLength As Long = SendMessage(ComboBoxEx, WM_GETTEXTLENGTH, CInt(0), CInt(0)) + 1 ' Get Length Of Text
Dim txtBuff As String = Space(txtLength)
Dim URL As Long = URL = SendMessage(ComboBoxEx, WM_GETTEXT, txtLength, txtBuff) 'Get URL From ComboBoxEx
MsgBox(txtBuff)
End If
End Sub
Basically, you're finding the IE window, then drilling down to find the combobox in which the URL is typed, and then getting whatever string is typed into it. Obviously this isn't a perfect approach (if somebody overwrites the URL but doesn't hit Enter, you wouldn't know it).
Upvotes: 1