Connecting to Running Instances of Internet Explorer

There has been always a problem connecting to web browsers,
Either you need to write Browser Helper Object or something which browser needs to instantiate.
But I found all the other methods had one or other way bug in it.
Decided to find simple and bug free way, And came across this ShellWindows interface,
which is used by Shell to keep track all the shell browsers including Shell Folders and Internet explorers
I Believe shell uses name spaces to keep track of this windows.

Not only shell windows keeps track of all shell windows and also notifies when new shell window is created or deleted.

When you enumerate, you can query whether the entry supports IWebBrowser interface,
if it does it could be either WebBrowser or ShellBrowser. Once you get hold of IWebBrowser2 interface,
you can either use it or listen to DWebBrowserEvents or through it away.

Before you start cranking in, you should include

#import "mshtml.tlb": // Internet Explorer 5
#import "shdocvw.dl"

Connecting To web browser using shell windows interface

void CIEEnumWindowsDlg::ConnectToShell()

if(m_spSHWinds == 0) {
// Get reference to ShellWindows interface
== S_OK) {
// Event Sink

if ((m_spSHWinds != NULL) &&
(LPVOID*)&pConnPtCont))) {
ASSERT(pConnPtCont != NULL);
DWORD dwCookie = 0;

if (SUCCEEDED(pConnPtCont->FindConnectionPoint(
__uuidof(SHDocVw::DShellWindowsEvents), &pConnPt)))
ASSERT(pConnPt != NULL);
pConnPt->Advise( this->GetIDispatch(FALSE), &dwCookie);

else {
AfxMessageBox("Shell Windows interface is not avilable");


Download source - 15 Kb

More by Author

Must Read