有人知道如何获取计算机上任何打开的IE进程的URL吗? 我根本不需要操作IE实例 - 只需获取有关当前加载的页面的信息。
谢谢!
答案 0 :(得分:1)
这似乎是一种方法(代码是Visual Basic,抱歉,但它显示了原理):
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
基本上,您正在找到IE窗口,然后向下钻取以找到键入URL的组合框,然后获取键入的任何字符串。显然这不是一个完美的方法(如果有人覆盖了URL但没有按Enter键,你就不会知道它。)
答案 1 :(得分:1)
一个简单的解决方案,它有效: http://omegacoder.com/?p=63
答案 2 :(得分:0)
通过自动化(即var oIE = WScript.CreateObject("InternetExplorer.Application", "IE_");
)自行启动IE并聆听NavigateComplete2
。
Peek inot ROT(运行对象表) - 我认为IE文档应该出现在那里 - Win32 / COM - http://msdn.microsoft.com/en-us/library/ms684004(VS.85).aspx
只需查找所有IE窗口并从地址中取出文本(请参阅MusiGenesis的答案)。