Using IELaunchURL to launch and retrieve the PID of a protected mode IE7 window

25 September 2008

With the release of Windows Vista, Windows Internet Explorer 7 introduced the Protected Mode feature for having a more secure experience in the browser. More information from one of the original IE Blog posts and the Protected Mode Internet Explorer Reference on MSDN.

Earlier today I put together a super simple app to get me the PID of the protected mode and wanted to share that.

On my team, we have a test harness that handles automating the web browser. To run a test using the Silverlight Unit Test Framework, our console application needs to launch the new browser process, retrieve its process ID (PID), and then wait for completion. During this time, we also poll the process to make sure that it is still alive.

Well, if the test harness is run from an unelevated command prompt (the ideal way to run it), then we were finding that the Internet Explorer process was immediately exiting. The simple pattern was:

  • Test harness launches iexplore.exe and retrieves PID 5860.
  • iexplore.exe uses launches a Protected Mode process (let's say PID 9600), and then the initial process ends.
  • The test harness thought that the process had ended prematurely, even though iexplore.exe PID 9600 was actually running the test scenarios.

The simple solution was to write a simple C++ shim for Windows Vista that would use the protected mode "IELaunchURL" API (by including iepmapi.h from the Windows SDK) and simply return the protected mode PID as the application's return value. In a failure state, it would return 0. The harness can then special case the Windows situation and use the return value PID to monitor the state of the protected mode browser.

Here's the C++ source code that I wrote as a proof of concept. It expects that you provide the URL to navigate to as the single parameter.

#include "stdafx.h"

#include <windows.h>
#include <iepmapi.h>

    PROCESS_INFORMATION processInformation;
	launchInfo.cbSize = sizeof(IELAUNCHURLINFO);
    launchInfo.dwCreationFlags = NULL;

	DWORD pid = 0;
    HRESULT hr = IELaunchURL(pszURL, &processInformation, &launchInfo);
    if (SUCCEEDED(hr))
        WaitForInputIdle(processInformation.hProcess, 2000);
		pid = processInformation.dwProcessId;
		return pid;
    return 0;

int _tmain(int argc, _TCHAR* argv[])
	if (argc == 2)
		return LaunchIE(argv[1]);
	return 0;

Download the 32-bit StartInternetExplorer.exe application. Note: This is totally unsupported, use at your own risk, all that jazz. This isn't a utility I'm using any longer, but did want to share since I didn't find a whole lot of information on the web.

If building in Visual Studio, you should also modify the C++ project properties (under the Linker) to include the additional dependency of iepmapi.lib.

Hope this helps!

Jeff Wilcox is a Software Engineer at Microsoft in the Open Source Programs Office (OSPO), helping Microsoft engineers use, contribute to and release open source at scale.

comments powered by Disqus