⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connecting to a running instance of internet explorer.txt

📁 关于ie控制的编程各种方面的内容和源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
Connecting to a running instance of Internet Explorer 

--------------------------------------------------------------------------------
This article was contributed by Peter Nalyvayko. 
There are some methods to connect to a running instance of IE. This one is how to connect through the ROT (Running Object Table). 

Usually, an application connects to a running instance of another application using the Running Object table. However the Internet Explorer 4.0 doesn't not register itself in ROT. The solution is to write so-called "Browser Helper Object" – a tiny COM object that exposes IObjectWithSite interface and register itself in the ROT. Also it's necessary to register this object in the Registry under the following key: 


HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\ 

The Internet Explorer will create new instance of each Browser Helper Object listed in registry every time new instance of Internet Expoler is started. 

HKLM\SOFTWARE\Microsoft\Windows
       \CurrentVersion\Explorer\Browser Helper Objects\{CE7C3CF0-4B15- 11D1-ABED-709549C10000} 

The following code demonstrates how to allow multiple instances of the Internet Explorer to be registered in the ROT using item moniker. 


/////////////////////////////////////////////////////////////////////////////  IEHELPER.H
#ifndef __IEHELPER_H_
#define __IEHELPER_H_

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// CIEHelper
class CIEHelper : 
        public CComObjectRootEx<CComSingleThreadModel>,
        public CComCoClass<CIEHelper, &CLSID_IEHelper>,
        public IObjectWithSiteImpl<CIEHelper>,
        public IIEHelper
{
public:
        CIEHelper()
        {
                m_dwROTID = 0;
        }

       ~CIEHelper()
        {
        }

        // IObjectWithSite interface
        STDMETHOD(SetSite)(IUnknown* pUnkSite);

DECLARE_REGISTRY_RESOURCEID(IDR_IEHELPER)

BEGIN_COM_MAP(CIEHelper)
        COM_INTERFACE_ENTRY(IIEHelper)
        COM_INTERFACE_ENTRY(IObjectWithSite)
END_COM_MAP()

// IIEHelper
public:
        void SetROTID(DWORD dwValue)
        {
                m_dwROTID = dwValue;
        }
private:
        DWORD m_dwROTID;
        void ROT_UnRegister();
        void ROT_Register();
};

#endif //__IEHELPER_H_

/////////////////////////////////////////////////////////////////// IEHELPER.CPP
// IEHelper.cpp : Implementation of CIEHelper

#include "stdafx.h"
#include "IE.h"
#include "IEHelper.h"

#include <initguid.h>
#include <exdisp.h>        // the IID_IWebBrowser is located over there
#include <stdio.h>

/////////////////////////////////////////////////////////////////////////////
// CIEHelper
//

// CObjectWithSite Methods
//

STDMETHODIMP CIEHelper::SetSite(IUnknown* pUnkSite)
{
        USES_CONVERSION;

        // remove previously registered object from the table
        ROT_UnRegister();

        // neccessary initialization
        HRESULT hResult = IObjectWithSiteImpl<CIEHelper>::SetSite(pUnkSite);

        // register helper object in the running object table
        ROT_Register();

        return hResult;
}

///////////////////////////////////////////////////////////////////////////
//

//
// Private Section
//

const static TCHAR* szMonikerTemplateName = _T("Browser Helper Object");

//
// register the object in the running object table 
//

void CIEHelper::ROT_Register()
{
        CComPtr<IRunningObjectTable> pTable;
        if(GetRunningObjectTable(0, &pTable) == S_OK)
        {
                CComBSTR bstrItemName;
                CComPtr<IMoniker> pMoniker;
                TCHAR szBuffer[1024];

                sprintf(szBuffer, "%s | %d", szMonikerTemplateName, m_spUnkSite);
                bstrItemName = szBuffer;
                if(CreateItemMoniker(NULL, bstrItemName, &pMoniker) == S_OK)
                {
                        DWORD dwRegister;
                        if(pTable->Register(1, (IUnknown*)this, pMoniker, &dwRegister) == S_OK)
                        {
                                SetROTID(dwRegister);
                                ATLTRACE("IIEHelper: the moniker %s has been registered successfully\n", szBuffer);
                        }
                        else
                        {
                                ATLTRACE("IIEHelper: failed to register moniker % s in the ROT\n", szBuffer);
                        }
                }
                else
                {
                        ATLTRACE("IIEHelper: failed to create moniker %s\n", szBuffer);
                }
        }
        else
        {
                ATLTRACE("IIEHelper: Could not retrieve the ROT pointer\n");
        }
}

void CIEHelper::ROT_UnRegister()
{
        CComPtr<IRunningObjectTable> pTable;
        if(GetRunningObjectTable(0, &pTable) == S_OK)
        {
                HRESULT hRes = pTable->Revoke(m_dwROTID);
                ATLTRACE("IIEHelper: ID = %d, result code %x\n", m_dwROTID, hRes);
        }
        SetROTID(0);
}

////////////////////////////////////////////////////////////////////// IEHELPER.RGS
// The following lines should be included into the self-registration portion of 
// COM application.

...

HKLM
{
        SOFTWARE
        {
                Microsoft
                {
                        Windows
                        {
                                CurrentVersion
                                {
                                        Explorer
                                        {
                                                'Browser Helper Objects'
                                                {
                                                        <CLSID>
                                                }
                                        }
                                }
                        }
                }
        }
}

Having implemented and registered the Browser Helper, an application can now obtain the pointer to a running instance of IE by traversing the ROT. 

The following example shows the rough method I used to list the instances of IE: 


IRunningObjectTable* pTable;

if(!FAILED(GetRunningObjectTable(0, &pTable)))
{
        IEnumMoniker* pEnum;
        if(!FAILED(pTable->EnumRunning(&pEnum)))
        {
                IUnknown* pUnknown;
                IMoniker* pCurMoniker = NULL;
                LPMALLOC pMalloc;
                while (pEnum->Next(1, &pCurMoniker, NULL) == S_OK) 
                {
                        if(!FAILED(pTable->GetObject(pCurMoniker, &pUnknown)))
                        {
                                IObjectWithSite* pSite;
                                if(!FAILED(pUnknown->QueryInterface(IID_IObjectWithSite, (void**)&pSite)))
                                {
                                        IDispatch* pDispatch;
                                        if(pSite->GetSite(IID_IDispatch, (void**)&pDispatch) == S_OK)
                                        {
                                                CWebBrowserApp browser;
                                             
                                                browser.AttachDispatch(pDispatch);
                                                TRACE("LocationURL: %s\n", browser.GetLocationURL());
                                                        TRACE("LocationName: %s\n", browser.GetLocationName());
                                                browser.DetachDispatch();
                                                pDispatch->Release();
                                        }
                                        pSite->Release();
                                }
                                pUnknown->Release();
                        }
                        pCurMoniker->Release();
                }
                pEnum->Release();
        }
        pTable->Release();
}

MORE INFORMATION
The following file is available for download from the Microsoft Software Library: 

 ~ IEHelper.exe (size: 39958 bytes) 
Date Posted: December 13, 1998 

Comments:
Outlook Express - tannguyen (2001/05/29) 
Parsing HTML tags from a running IE instance. - Jackson Lai (2001/05/21) 
How can I show the ie extension bar in the script code. - bo (2001/05/16) 
Accessing an Object w/ ROT - Mike K (2001/05/11) 
Help a newbie - How can i calculate the the length of an HTML page? - Van Shefi (2001/04/23) 
Popup Window URL from Server - Rajiv (2001/04/16) 
How can i get window.location.href of an instance of IE with VC++? - beebok (2001/03/15) 
How I write a IE plugin with VC? - Peter wang (2001/02/07) 
Calling HTML page behind ActiveX Control button in IE - Kashif (2001/01/24) 
IEHelper doesn't compile with VC++ - SKI (2001/01/01) 
How to get IP Address of the current web site - Ram Prasad (2000/11/24) 
How can I get html document of my current browser? - wavor (2000/11/20) 
How can I get the Events (i.e. onclick, onmouseover,...) in an HTML page? - Matteo (2000/11/08) 
Is there a way of controling the client's browser from the server??? - Rolando Riccio (2000/10/20) 
Netscape Navigator - Lau (2000/09/28) 
BHO - security issues in Windows NT and 2000 - Shilpi Dey (2000/08/10) 
Browser Helper Object - HM (2000/07/26) 
Printing from Browser Helper Object - Ravi (2000/04/28) 
Problem with multiple instance of IE in different process - Denis GALIANA (2000/04/07) 
InternetExplorer Object - Jordon (2000/03/18) 
Explorer bar - Eran (2000/03/14) 
Get errors upon compilation."Can not convert ... type to another" - Bob (2000/02/09) 
How to write a plug-in for internet explorer? - Hemakumar (2000/08/21) 
Can I Use this helper to write plugins for ie? - Bhushan Ivatury (2000/01/28) 
Any better way? - Shahryar Eivazzadeh (2000/01/08) 
How do i change URL in IE5 by another application - john.xi (1999/12/28) 
IEHelper doesn't compile with Visual C++ 6. - Will Allan (1999/12/13) 
How can I use Browser Helper Objects in IE 5 - Mikezh (1999/12/12) 
How can I fill edit box on IE page ? - John (1999/11/03) 
how do you differentiate between Internet Explorer and Windows Explorer - Mat (1999/10/27) 
how do you differentiate between Internet Explorer and Windows Explorer - Mat (1999/10/27) 
how do you differentiate between Internet Explorer and Windows Explorer - Mat (1999/10/27) 
how do you differentiate between Internet Explorer and Windows Explorer - Mat (1999/10/27) 
How do I connect to Netscape Nav? - David Grubbs (1999/10/19) 
problem if register 2 of such dll - alan tam (1999/10/12) 







Accessing an Object w/ ROT

--------------------------------------------------------------------------------
I have been able to enum the ROT and get a pointer to my running obj with the ROT GetObject API. But when I call 
pUnknown->QueryInterface(IID_IPVStats, (void**)&pPVStat); 
the address of pPVStat get messed up when the QueryInterface funtion receives it. I set break points on both projects(2 seperate application) one before the QueryInterface in one proj and one inside the QueryInterface in the other proj(with the running obj) and the address passed in is not the address that is received. Somehow the address is getting trashed. What could be happening here? I pass in 0x0012fe64(=&pPVStat) in the one application, but the running object receives 0x0012f684. Just to see what would happen, I passed in 0x00000000 and the running obj received 0x0012f604. What the heck is going on??? Anyone with any ideas, please help! 
Submitted By: Mike K (2001/05/11) 






Help a newbie - How can i calculate the the length of an HTML page?

--------------------------------------------------------------------------------
Upon loading a page into the browser how do find out the final full length of the page? meaning beyound the scroll? 
Yoav 

Submitted By: Van Shefi (2001/04/23) 





Popup Window URL from Server

--------------------------------------------------------------------------------
Hi 
I would like to determine a Popup windows URL from a Server running my com object. I dont have any code running in the Popup window. Kindly advise best methods possible. Look forward to immediate help. I am using VB so something close would be appreciated. 
TIA 
Rajiv 

Submitted By: Rajiv (2001/04/16) 




How can i get window.location.href of an instance of IE with VC++?

--------------------------------------------------------------------------------
please mail me, beebok@aon.at 
thx a lot! 
beebok 

Submitted By: beebok (2001/03/15) 




How can I open any html document on internet, in already being executed browser?

--------------------------------------------------------------------------------
Thanks for read this... 
I am Korean. 
My job is software engineerer. 
I am making a virtual proxy server in localhost, But I have a problem. 

In current browser, I want to display a html document on internet. 

How can I open any html document on internet, in already being executed browser? 

Submitted By: Segeun Shin (2001/03/23) 




IEHelper doesn't compile with VC++

--------------------------------------------------------------------------------
I am using VC++ to compile IEHelper sample code for IE 5.5 on Windows 2000Pro. Its giving me cannot convert type errors on compilation...plus, how to capture events from within the main explorer window and pass on to bho...any help would be appreaciated. 
Thanks 

Submitted By: SKI (2001/01/01) 





How can I get html document of my current browser?

--------------------------------------------------------------------------------
Hi. 
How can I get all html document of Internet Explorer browser as a "View Source" event on IE? 

Submitted By: wavor (2000/11/20) 





How can I get the Events (i.e. onclick, onmouseover,...) in an HTML page?

--------------------------------------------------------------------------------

after I have connented a current running  instance of IE, How can I get the Events(i.e. onclick, onmouseover,...) in an HTML page from my application written in VC++?


Submitted By: Matteo (2000/11/08) 




Is there a way of controling the client's browser from the server???

--------------------------------------------------------------------------------
Hi I was wondering if there is a way of controlling the client's browser from the server. Say I want my site to be viewed on full screen mode (same as user would press F11 in the browser). Could I develop a DLL component in Visula Basic to change settings in the client's browser once this server component is referenced? 
I tried and was only capable of doing it with a client application in VB. 

Thanks for your help 

PD. First tike i get to this forum i'm not sure the reply goes straight to my e-mail could you send the answer to my e-mail? 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -