Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1099
  • Last Modified:

How to Monitor Events in Explorer

Hi All!

I find that I can create an instance of Windows Explorer and monitor its' internet traffic events like this:

  HRESULT hr = CoCreateInstance( CLSID_ShellBrowserWindow, // Creates an Instance of Windows Explorer.
                                 NULL,
                                 CLSCTX_LOCAL_SERVER,
                                 IID_IWebBrowser2,
                                 (void**)&m_pIE);
 
  m_pIE->put_Visible(VARIANT_TRUE);

  BOOL bAdvised = AfxConnectionAdvise( m_pIE,
                                       DIID_DWebBrowserEvents2,
                                       m_pIEEvents->GetInterface(&IID_IUnknown),
                                       TRUE,
                                       &m_dwCookie);


Great.  But what I want to do is to monitor internet events on an instance of Explorer that is already running.  So I did manage to get this to work:

  CString msg;
  HRESULT hresult;
  VARIANT arg;
  arg.vt = VT_ERROR;
  arg.scode = DISP_E_PARAMNOTFOUND;

  IUnknown *punk = (IUnknown *)NULL;

  CLSID clsid;                                

  CLSIDFromProgID( L"InternetExplorer.Application.1",
                  &clsid);

  hresult = GetActiveObject( clsid,
                            NULL,
                            &punk);

  if(!SUCCEEDED(hresult)){

   AfxMessageBox("Not FOUND", MB_OK);

   return TRUE;

  }

  hresult = punk->QueryInterface( IID_IWebBrowser2,
                                 (LPVOID *)&m_pIE);

  if(!SUCCEEDED(hresult)){
      AfxMessageBox("QueryInterface() failed", MB_OK);
      punk->Release();
      return TRUE;
  }

  punk->Release();

  // Set up the event sink
  BOOL bAdvised = AfxConnectionAdvise( m_pIE,
                                      DIID_DWebBrowserEvents2,
                                      m_pIEEvents->GetInterface(&IID_IUnknown),
                                      TRUE,
                                      &m_dwCookie);

Fine.  That allows me to monitor a previously running version of IE.  But, I haven't been able to find out what the ProgID is for Explorer.exe.  Man do I feel dense.  My brain hurts.  This can't be that hard.  Will sombody please put me out of my misery?

Thank, Larry
0
prangel
Asked:
prangel
  • 3
  • 2
1 Solution
 
ZoppoCommented:
Hi prangel,

with 'ProgID' you mean the 'InternetExplorer.Application.1'
from your code?

If so, why not simply use i.e.

hresult = GetActiveObject( CLSID_InternetExplorer,          NULL,&punk);

hope that helps,

ZOPPO
0
 
prangelAuthor Commented:
Hey ZOPPO! Thanks for looking at my little problem.

Yea, I knew that GetActiveObject(CLSID_InternetExplorer . . .  ) works fine.  And when I use CoCreateInstance(CLSID_ShellBrowserWindow . . .  ) to create and control an instance of Windows Explorer (not IE) that works fine too.  But when I try to hook up to an already-runnung instance of Windows Explorer with GetActiveObject(CLSID_ShellBrowserWindow . . .  ), I get back error #-2147221021, 'Operation Unavailable'.  That is what I am trying to do.  I need to do an AfxConnectionAdvise() to a previously running instance of Windows Explorer (not IE) to monitor internet traffic that originates from Windows Explorer.

Thanks for your help,

Larry
0
 
ZoppoCommented:
hm... strange, for me it seems to work fine.

BTW, I recieve the same error if I comment out the call
to AfxOleInit() in the win-app-derived InitInstance()
function ... maybe you missed this.

ZOPPO
0
 
prangelAuthor Commented:
ZOPPO!

I think that I got a handle on it.  

(By the way AfxOleInit() was in there.)  

As a result of some testing I was doing to figure out why it worked for you and didn't for me, I discovered that an instance of Explorer.exe (Not IE) would respond properly to GetActiveObject(CLSID_InternetExplorer . . .  ).  Weird, but I guess that it is the IE control, contained be Explorer, that is answering the 'phone'.  Not Explorer itself.  So, the key accessing the internet functionaliy in Explorer is to use IE's CLSID, not Explorer's, with GetActiveObject().

I appriciate your help for helping me get on the right track and I am going to award you the points.

Thanks!

Larry
0
 
ZoppoCommented:
hm, ok, thanks a lot ... sorry that you had to solve the problem yourself :o)

have a nice day,

regards,

ZOPPO
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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