Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取浏览器中已打开选项卡的URL_C#_Vb.net_Winforms_Winapi_Desktop Application - Fatal编程技术网

C# 获取浏览器中已打开选项卡的URL

C# 获取浏览器中已打开选项卡的URL,c#,vb.net,winforms,winapi,desktop-application,C#,Vb.net,Winforms,Winapi,Desktop Application,我正在做一个项目,我需要获取浏览器(如谷歌浏览器、IE浏览器、火狐浏览器等)中所有打开标签的URL 使用c#或vb.net有什么方法可以做到这一点吗 p、 它是一个windows窗体应用程序,即: Dim browser As SHDocVw.InternetExplorer Dim myLocalLink As String Dim myDoc As mshtml.IHTMLDocument2 Dim shellWindows As SHDocVw.ShellW

我正在做一个项目,我需要获取浏览器(如谷歌浏览器、IE浏览器、火狐浏览器等)中所有打开标签的URL

使用c#或vb.net有什么方法可以做到这一点吗

p、 它是一个windows窗体应用程序,即:

    Dim browser As SHDocVw.InternetExplorer
    Dim myLocalLink As String
    Dim myDoc As mshtml.IHTMLDocument2
    Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
    Dim filename As String

    For Each ie As SHDocVw.InternetExplorer In shellWindows
        filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower()

        If filename = "iexplore" Then
            browser = ie
            myDoc = browser.Document
            myLocalLink = myDoc.url
            MessageBox.Show(myLocalLink)
        End If
    Next
c#:

你需要:

microsoft.mshtml

FireFox c#:


下载NDde.2.01.0563(NDde.dll)

我还制作了Chrome:

Vb.net:

共享功能:


这将是极其困难的。如果你能解释一下为什么要这样做,以防有更好的方法。如果我创建了一个浏览器,我不会让我的浏览器共享这些信息。对我来说似乎不安全…它特定于浏览器,可靠性令人怀疑;请注意与代理服务器方法相关的注释。
microsoft.mshtml
shdocvw.dll
using NDde.Client;
        DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
        dde.Connect();
        string url = dde.Request("URL", int.MaxValue);
        dde.Disconnect();
        MessageBox.Show(url);
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
 ByVal lpClassName As String, _
 ByVal lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
                  ByVal childAfter As IntPtr, _
                  ByVal lclassName As String, _
                  ByVal windowTitle As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
    Dim h As IntPtr
    For Each p As Process In Process.GetProcessesByName("chrome")
        h = FindWindow("Chrome_WidgetWin_1", p.MainWindowTitle)
        Exit For
    Next
    Dim urlH As IntPtr
    urlH = FindWindowEx(h, 0, "Chrome_OmniboxView", Nothing)
    Dim urlHH As IntPtr = Marshal.AllocHGlobal(100)
    Dim NumText As Integer = SendMessage(urlH, &HD, 50, urlHH)
    Dim url As String = Marshal.PtrToStringUni(urlHH)
    MsgBox(url)