Detecting Windows 8 Metro application

c++ / delphi package - dll injection and api hooking
Post Reply
kaitnieks
Posts: 1
Joined: Wed Feb 02, 2011 11:01 pm

Detecting Windows 8 Metro application

Post by kaitnieks »

Is there any way (official or by using any kind of telltale signs) to determine if the current process is Metro or Desktop application?
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Detecting Windows 8 Metro application

Post by madshi »

Good question. I didn't need this myself yet, so I don't know how to do that. I'm sure there is a way, but I don't know how. Would have to do a google search myself to find out...
Absolute_Zero
Posts: 39
Joined: Fri Jan 26, 2007 11:12 am

Re: Detecting Windows 8 Metro application

Post by Absolute_Zero »

Here's my 'Metro' detection routine...

Code: Select all


    HMODULE hApp = GetModuleHandleA(NULL);

    if (IsMetro(hApp))
        . . .
/*
** IsMetro - return if the process is a Metro/Modern-UI app
***************************************************************************************************/
static BOOL IsMetro(HMODULE hApp)
{
	IMAGE_DOS_HEADER ImageDosHeader;
	IMAGE_OPTIONAL_HEADER32 ImageOptionalHeader;
	BOOL bRet;

	CopyMemory(&ImageDosHeader, hApp, sizeof(ImageDosHeader));
	CopyMemory(&ImageOptionalHeader, ((BYTE *)hApp + sizeof(DWORD) + ImageDosHeader.e_lfanew + sizeof(IMAGE_FILE_HEADER)), sizeof(ImageOptionalHeader));

	bRet = ImageOptionalHeader.DllCharacteristics & 4096; // Metro/Modern-UI app flag

	if (bRet)
		dbg("Metro/Modern-UI app");

	return bRet;
}
Absolute_Zero
Posts: 39
Joined: Fri Jan 26, 2007 11:12 am

Re: Detecting Windows 8 Metro application

Post by Absolute_Zero »

^ doesn't seem to work any more.

Instead, use something akin to the following. Caveat: explorer and taskmgr report as immersive... bing maps' map.exe starts non-immersive but switches to immersive shortly after.

Code: Select all

	typedef BOOL (WINAPI * t_IsImmersiveProcess)(HANDLE hProcess);
	t_IsImmersiveProcess fn_IsImmersiveProcess = (t_IsImmersiveProcess)GetProcAddress(hUser32, "IsImmersiveProcess");

	if (fn_IsImmersiveProcess)
		if (fn_IsImmersiveProcess(GetCurrentProcess()))
		{
Post Reply