VB.net get URL from active Browser

Dave Fyfe
Dave Fyfe used Ask the Experts™
on
I am developing a small utility and one of the things I I would like to do is to capture the URL from the current active browser, it could be IE or Chrome, But How do I capture the URL from the browser and display a simple MsgBox in my VB application.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave FyfeTechnician

Author

Commented:
Already tried the codeproject article and the demo didn't work for me.
Commented:
Microsoft Internet Controls is the reference where the SHDocVW can be found. It is built in Visual Studio.

For the version VS2010, right click a project -> add reference -> COM -> Microsoft Internet Controls

using System;
using System.IO;

namespace ConsoleApplication1
{
  public class Program
  {
    static void Main()
    {
      SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
      string filename;
 
      foreach ( SHDocVw.InternetExplorer ie in shellWindows )
      {
        filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
        if ( filename.Equals( "iexplore" ) )
          Console.WriteLine( ie.LocationURL );
 
      }
      Console.Read();
    }
  }
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial