• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Accessing Web Browse URL

I am wondering if there is a way to find out what the url of an independently open web browser is.  That is to say that my application needs to know what web page Netscape or IE or any other browser currently has loaded.  It is a functionality that i know can be accomplished, ICQ and AIM both have it.  I woudl like a VB solution, but if there is one in C++ I'd take that as well.  I want to be clear here...this is not a web browser control...this is a seperate independent web browser running concurrently.  

  • 3
1 Solution
The one way I've heard of doing it involves using FindWindow or EnumWindows
to search for a window with a class string of "IEFrame" for internet explorer, or something equivalent for netscape.  Then traverse the window hierarchy to find the URL textbox and read from that.  
musakaAuthor Commented:
Can you explain a little more how one traverses the windo hierarchy?  
I'm developing a little utility to help write code to do it, but it's still a little rough around the edges.  Here's some pointers about the WinAPI calls it uses...

Conceptually, you start at the top of the hierarchy, find the internet explorer window, then find the text box within that, then use GetWindowText to get its contents.

Search msdn.microsoft.com for any of the following:
Check article Q168829 in particular.

If you have MS Vis Studio, you can use the included program 'Spy++' to see the hierarchy and see what class names/window texts to look for.

I can give more details (or code) if needed.
Okay, I got it to work yesterday.  Please excuse any mistakes I make in API calls, I'm using a library that uses them indirectly and shrinks the URL finding code to one page.

To start off, I get a list of all the top-level windows (use one of getDesktopWindow&EnumChildWindows or GetWindow).  For each top level window whose class (getClassName) is "IEFrame", I assume it's an internet explorer window and search for the combo box under that.  For each top level window whose class starts with "Afx:", I assume it's a netscape window.

For all top level MS-IE windows, I find all sub windows (using EnumChildWindows or FindWindow or GetWindow) with a class name of "WorkerW", then under that a class name of "ReBarWindow32", then under that a class name of "ComboBoxEx32".  I then use SendMessage with a message of WM_GETTEXT to get the text from the combo box.

The NS windows seemed a bit confusing, their class names all started with "AFX:" and had a bunch of numbers after them.  So I resorted to recursively searching through all subwindows for a window whose class name is "ComboBox" and whose parent's class name starts with "#" (there's probably a better way of doing this).  I again used SendMessage(hwnd, WM_GETTEXT,...) on the combobox.

The problems with this approach are:
  - Only works for MSIE or NS
  - Probably only works for specific versions of MSIE or NS, but you could use these same methods on older versions, you'd just have to install them and use Spy++ to trace their window hierarchy.
  - I couldn't get the results to be in sorted order by z-order (using EnumChildWindows), that is, I didn't know which of the URLs the user had been at most recently.  I'm trying to solve this problem now.  (this could have several interesting uses... :)

If you're interested in the code, I'd be happy to post it along with the required library, but the library is still in the alpha version.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now