How to Connect to IExplorer in Citrix Environments

Environment: VC6 SP4; Windows 98, NT4, 2000, XP; Internet Explorer 5.x, 6.x

Recently, I had to connect to a running instance of Internet Explorer inside a Citrix environment in seamless mode (it's a way to launch an application in a new session without the Desktop).

All the methods exposed in other articles (such as Using ShellWindows) are not bug free. For example, if you kill explorer.exe and you try to get ShellWindows, this object is unavailable. This also happens in Citrix environments if you open an Internet Explorer window in the seamless mode because you don't have a Desktop launched (and, of course, no explorer.exe is running in that session).

On the other side, if you use Browser Helper Objects (BHO), you have to register your DLL and it will be loaded by all instances of both Windows Explorer and Internet Explorer. This is not desirable, especially if you want to attach your automation code only after opening some specific window.

I have found a better way to obtain the WebBrowser object associated to a running instance of Internet Explorer. It is based upon some yet-to-be-documented features of the Shell. This method ONLY works inside the process of Internet Explorer, so you will have to hook your code previously with SetWindowsHookEx().

I hope this can help somebody. The code is as follows:

#include <comdef.h>
#include <shlobj.h>
#define CWM_GETISHELLBROWSER (WM_USER+ 7)
#define GetIShellBrowser(_hwnd) (IShellBrowser FAR *) ::
        SendMessage(_hwnd,CWM_GETISHELLBROWSER, 0, 0L)

IShellBrowser* pShellBrowser=GetIShellBrowser(hWnd);
// hWnd is the handle of the target IExplorer window

if(pShellBrowser!=NULL)

{

//DO NOT release pShellBrowser
IServiceProviderPtr pIsp;
IServiceProviderPtr pIsp2;
IWebBrowser2Ptr pBrowser;
HRESULT hr= pShellBrowser->QueryInterface(IID_IServiceProvider,
            reinterpret_cast<void **>(&pIsp));
if(hr==S_OK && pIsp!=NULL)
{
  hr=pIsp->QueryService(SID_STopLevelBrowser,
     IID_IServiceProvider, reinterpret_cast<void
     **>(&pIsp2));
  if(hr==S_OK && pIsp2!=NULL)
  {
    hr=pIsp2->QueryService(SID_SWebBrowserApp,
       IID_IWebBrowser2, reinterpret_cast<void **>(&pBrowser));
    if(hr==S_OK && pBrowser!=NULL)
    {
      //Here you have the browser attached to the IExplorer window
    }
  }
}
}

References

Namespace Extensions—the Undocumented Windows Shell

INFO: Accessing the Object Model from Within an ActiveX Control

Connect to Internet Explorer Instances, from Your Own Process.



Comments

  • Heel lifts

    Posted by Crodociorge on 02/21/2013 10:05am

    shoe lifts for men and women might also have various width sizing which you have to take into consideration when choosing the set that's right for you personally http://azumaseizo.sakura.ne.jp/userinfo.php?uid=606

    Reply
  • Shoe lifts

    Posted by Crodociorge on 02/17/2013 01:16pm

    Shoe or shoe lifts insoles can safely add height when utilized with common sense, wearers should understand that their center of gravity will change as well as walking below normal circumstances will take some obtaining utilized to http://www.wallysbait.com/Forum/profile.php?mode=viewprofile&u=65690&sid=111c9ffe10cbf3657461979404b40e97

    Reply
  • Need code in c#

    Posted by sharath1984 on 04/15/2011 03:28am

    Hi, I am having a application published in citrix but I am not able to get its handel in c# code can you pls send me the above code in c#.net. Thanks, Shankar.

    Reply
  • Very good code

    Posted by Legacy on 11/07/2003 12:00am

    Originally posted by: Paco Urbano :D

    :D

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds