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

GetActiveObject and Internet Explorer

Hi All

I want to get the URL from the running IE. I attached a small Win32 app that was supposed to do it. I see  the GetActiveObject returns 0x800401e3 - operation unavailable.

I've read MSDN:
Retrieves a pointer to a running object that has been registered with OLE.

So Internet Explorer is noit registered?
Where is the mistake?

I see few threads on EE with GetActiveObject in the accepted solutions.
I tested the same in an MFC application too. More then it, I found the Edit in IE and I cannot get the URL with GetWindowText too.

It is IE 8. I see the problem on Vista and XP.

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <mshtml.h>
#include <exdisp.h>

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
					  LPWSTR lpCmdLine, int nCmdShow)
{
	LPUNKNOWN pUnknown;
	IWebBrowser2* pBrowser;
	HRESULT hr = CoInitialize(NULL);
	if (!SUCCEEDED(hr))
		return FALSE;

	//CLSID clsid;                                
	//CLSIDFromProgID( L"InternetExplorer.Application", &clsid);
	//hr = GetActiveObject(clsid, NULL, &pUnknown);
	hr = GetActiveObject(CLSID_InternetExplorer, NULL, &pUnknown);

	if (SUCCEEDED(hr))
	{
		hr = pUnknown->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pBrowser);
		BSTR str = NULL;
		hr = pBrowser->get_LocationURL(&str);
		SysFreeString(str);
		pBrowser->Release();
		pUnknown->Release();
	}

	CoUninitialize();
	return 0;
}

Open in new window

0
pgnatyuk
Asked:
pgnatyuk
  • 5
  • 4
1 Solution
 
milindsmCommented:
0
 
pgnatyukAuthor Commented:
Thank you. Nice article. I knew about it, but never used. I cannot use it now too.
So IE is not registered?
If this is only the answer, I can close this question. I have a bad solution - I got the text from the edit box of the Navigation Bar.
 

HWND FindIEWnd()
{
	HWND hWnd = FindWindow(L"IEFrame", NULL);
	return hWnd;
}

HWND FindURLWnd(HWND hIE)
{
	if (!IsWindow(hIE))
		return NULL;

	HWND hWndURL = NULL;
	HWND hWnd = FindWindowEx(hIE, NULL, L"WorkerW", NULL);
	if (hWnd != NULL)
	{
		hWnd = FindWindowEx(hWnd, NULL, L"ReBarWindow32", NULL);
		if (hWnd != NULL)
		{
			hWnd = FindWindowEx(hWnd, NULL, L"Address Band Root", NULL);
			if (hWnd != NULL)
			{
				hWndURL = FindWindowEx(hWnd, NULL, L"Edit", NULL);
			}
		}
	}
	return hWndURL;
}

Open in new window

0
 
CSecurityCommented:
Best way is BHO. You can also give thread injection or dll injection a try.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
milindsmCommented:
@pgnatyuk
This is quite risky solution. Don't expect that it will always give you correct results...!!!
0
 
pgnatyukAuthor Commented:
Yes, I know. It is not a real project. I agree with you.
0
 
milindsmCommented:
But why not BHO ??? Are you getting any errors????
0
 
pgnatyukAuthor Commented:
I've said - it is not a real project.
I thought that the correct way is to use IWebBrowser2. It didn't work because of GetActiveObject. I didn't expect that. I didn't want to spend time on BHO.
Thanks from the article.
0
 
pgnatyukAuthor Commented:
Thanks
0
 
milindsmCommented:
Thanks...!!! Please rate the article as well if you found it useful...!!!
0
 
pgnatyukAuthor Commented:
Actually here is the correct (or, at least, the expected) answer:
Connecting to Running Instances of Internet Explorer:
http://www.codeproject.com/KB/shell/ietoolbartutorial.aspx
CodeProject: http://www.codeproject.com/KB/shell/iehelper.aspx
MSND:
1. ShellWindows: http://msdn.microsoft.com/en-us/library/bb773974(VS.85).aspx
2. Internet Explorer object: http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx
 
 
0
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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