Posted 25 September 2008 Tweet
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:
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>
HRESULT LaunchIE(LPCWSTR pszURL)
{
PROCESS_INFORMATION processInformation;
IELAUNCHURLINFO launchInfo;
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;
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
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 development engineer at Microsoft who leads exciting open source projects on the Windows Azure team. Jeff has been at Microsoft 8 years and is an alumnus of the University of Michigan.
Jeff leads the open source Windows Azure SDK and cross-platform command line tools development team at Microsoft. Offering tooling for OS X, Windows and Linux and SDKs for Node.js, Java, .NET, PHP, Python; the work is open source, licensed under the Apache 2 license.
4th & Mayor is the top-rated social app on the Windows Phone Store with thousands of five star reviews. The best foursquare experience for Windows Phone, it is powered by a Node.js backend running on Windows Azure & Amazon Web Services. Jeff Wilcox is the developer of the app.