שתף באמצעות


Get URL of IE, Firefox and chrome brower

Question

Thursday, July 14, 2011 6:44 AM

I want to get the all URLs of any open browser using vb.net desktop application..... can anyhow guide me how can i do this???http://www.SurdzSoft.com

All replies (7)

Thursday, July 14, 2011 7:17 AM ✅Answered | 2 votes

Dear Ather,

Add a reference in your project to Microsoft Internet Controls. Then try this:

Public Function getAllRunningIEURLs() As ListBox
    Try
      Dim list As New ListBox
      For Each browser As InternetExplorer In New ShellWindows()
        list.Items.Add(browser.LocationURL.ToString)
      Next
      Return list
    Catch ex As Exception
      Return Nothing
    End Try
  End Function

Hope this helps,

Cheers,

John


Thursday, July 14, 2011 8:06 AM

Alther,

This is the first question in the range:

How can I prevent users for certain url's also often called parent control or nany control.

It is not as easy as you ask, as the URL is in the browser program, not direct available for Visual Basic.

You can try to get the port addresses, but for that VB is not the program language.

Try Intel Assembler, C or C++ unmanaged instead of that.

If you want to know more of it, than search on Google for watching port 80.

 

Success
Cor


Thursday, July 14, 2011 8:11 AM

Thank you so much.... can you tell me should i apply same thing for Firefox and chrome browser too???http://www.SurdzSoft.com


Thursday, July 14, 2011 3:01 PM

nope, you cannot interface with firefox and chrome in that fashion. I have to agree with Cor on that.

cheers,

John


Friday, July 15, 2011 1:10 AM | 5 votes

Let me add chrome and firefox code to complete your request

For chrome, some windows API will get you the url, the code i provide below will only get you the current tab url but to get all url of all open tab, you have to use EnumWindows API with delegate. Try google for that.

For Firefox, this is very difficult to do with windows API but there is dynamic data exchange (NDde) for .net that can get you the current firefox url. The library can be download from http://ndde.codeplex.com/ and add reference to NDde.dll 

 

By the way, if you like to go deep into IE tab, you can try Accessibility class in .net, where you can control IE tabs. Sample code here http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/03a8c835-e9e4-405b-8345-6c3d36bc8941

Chrome and Firefox code

Imports NDde.Client 'import the NDde library for firefox
Imports System.Runtime.InteropServices

'For Chrome
Private Const WM_GETTEXTLENGTH As Integer = &He
Private Const WM_GETTEXT As Integer = &Hd

<DllImport("user32.dll")> _
Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInteger, wParam As Integer, lParam As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInteger, wParam As Integer, lParam As StringBuilder) As Integer
End Function
<DllImport("user32.dll", SetLastError := True)> _
Private Shared Function FindWindowEx(parentHandle As IntPtr, childAfter As IntPtr, className As String, windowTitle As String) As IntPtr
End Function

Public Shared Function getChromeUrl(winHandle As IntPtr) As String
    Dim browserUrl As String = Nothing
    Dim urlHandle As IntPtr = FindWindowEx(winHandle, IntPtr.Zero, "Chrome_AutocompleteEditView", Nothing)
    Const nChars As Integer = 256
    Dim Buff As New StringBuilder(nChars)
    Dim length As Integer = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0)
    If length > 0 Then
        SendMessage(urlHandle, WM_GETTEXT, nChars, Buff)
        browserUrl = Buff.ToString()

        Return browserUrl
    Else
        Return browserUrl
    End If

End Function

Public shared Function GetChromeHandle() As Intptr
 Dim ChromeHandle As IntPtr = Nothing
 Dim Allpro() As Process = Process.GetProcesses();
 For Each pro As Process in Allpro
  if pro.ProcessName = "chrome"
  ChromeHandle = pro.MainWindowHandle
  Exit For
  End if
 Next     
Return ChromeHandle
End Function

'USAGE FOR CHROME
 Dim CHandle As IntPtr = GetChromeHandle()
 If Not CHandle,Equals(Intptr.Zero)
 Dim url As String = getChromeUrl(CHandle)
 End If

'=========FIREFOX======================
'For firefox ; Download the library from http://ndde.codeplex.com/ 
Public Shared Function GetFirefoxUrl() As String
    Dim dde As New DdeClient("Firefox", "WWW_GetWindowInfo")
    dde.Connect()
    Dim url As String = dde.Request("URL", Integer.MaxValue)
    dde.Disconnect()
    Return url
End Function

kaymaf

CODE CONVERTER SITE

http://www.carlosag.net/Tools/CodeTranslator/.

http://www.developerfusion.com/tools/convert/csharp-to-vb/.


Saturday, April 19, 2014 1:34 AM

Sadly this Seems not to work on Chrome. I made it work with Firefox but Chrome has changed some of their optins and I am not sure if this would work anymore.

It could be awesome to get an upgraded code for Chrome! Thanks


Thursday, January 7, 2016 5:03 AM

I want to do the same in Linux !! Have you got any idea ??