Bionicoder's Blog

Windows software development and business blog

IE7 Shell Window Registration in Vista

Posted by bionicoder on June 17, 2009

A Shell window is a window that has been registered by calling IShellWindows::Register or IShellWindows::RegisterPending.  Upon registration, the specified window is added to the collection of Shell windows.  The Shell windows collection includes file explorer windows and web browser windows Internet Explorer and 3rd-party web browsers.  The shell window collection can be retrieved through:

        IShellWindows *psw;
        HRESULT hr;
        hr = CoInitialize(NULL);
        if (SUCCEEDED(hr))
        {
             hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw);

             if (SUCCEEDED(hr))
             {
                  // TODO: Use the IShellWindows instance...

                  psw->Release();
             }
         }

Before Windows Vista, all opened file explorers and Internet Explorers can be found through the above code. But this changed in Windows Vista because of UAC. The issue is when UAC is ON, sometimes the IE can not be enuermerated. This issue was also discussed in MSDN forum. Some developers thought IE can only be enumerated when UAC is OFF.

I spent a couple of hours to do some resarch and found:

  1. When UAC is ON, the IE run in Protected Mode: ON can still be enumerated through above method
  2. When UAC is ON, the IE run in Protected Mode: OFF can NOT be enumerated through above method.

This is very interesting.  I am not sure why Microsoft does not allow IE in protected off mode being enumerated when UAC is ON.  Maybe it is because of Microsoft own security consideration.  This inconsistent behavior has not been updated in Microsoft website yet.

So, in Vista (UAC on), developer needs to use two different ways to get IWebBrowser2 interface.

Advertisements

3 Responses to “IE7 Shell Window Registration in Vista”

  1. paviavio said

    Looks tough.

  2. Isn’t it the other way around?
    When IE runs with Protected Mode: ON, it can NOT be enumerated through IShellWindows.
    And when it runs in Protected Mode: OFF, then it can be enumerated through IShellWindows.

    At least that’s what I see on my side…

    And it’s the same thing with IE8… 😦

    • Bionicoder said

      I am not 100% sure about Protected Mode OFF. The root cause for me not be able to enumerate through IShellWindows might be other things in my code. If you are able to enumerate through IShellWindows when Protected Mode OFF (UAC on). That is great! I can verify it some time later.

      Regarding to Protected Mode ON, I am 100% sure IE7 or IE8 can be enumerated by IShellWinodws. I originally thought it was impossible. But I happened to read a article about connecting to a instance of active IE. That article does not really address Vista UAC or Protected Mode. But it gives me an idea about using IShellWindows to enumerate IE window. Eventually I made it worked in Vista when Protected Mode is ON.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: