How to run Metro Style App directly in desktop?
-
Monday, October 31, 2011 7:56 AM
As we know, Metro Style App must be run from container by click the App tile, but Visual Studio 2011 can start up Metro Style App directly by press "F5" or "Ctrl + F5", how can i complete the same feature in my Win32 App to run a Metro Style App directly?
- Moved by Rob CaplanMicrosoft Employee Monday, October 31, 2011 11:28 PM desktop development issue, not metro app development (From:Tools for Metro style apps )
All Replies
-
Monday, October 31, 2011 10:06 PM
Hello,
there will be more info on this in the upcoming release. In the developer preview (11.0.40825.2), they are doing a CreateProcess to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger>vsdebuglaunchnotify /ActivateImmersive:e1f06d0d-5ebf-4001-953a-b3365e2d008b_s312dhpftz30r!App (go to your package.appxmanifest to get the package family name). This worked for me in a non-administrator command prompt. I believe that vsdebuglaunchnotify is calling into the Application Activation Manager (IApplicationActivationManager::ActivateApplication) to do the activation. In future releases, it will possibly be a direct call using the COM Application Activation Manager object.
much appreciated,
mike
- Marked As Answer by TanJingdong Tuesday, November 01, 2011 5:04 AM
-
Monday, October 31, 2011 11:24 PM
IApplicationActivationManager is available in the developer preview and defined in shobjidl.h and shobjidl.idl.
In most cases applications will be better off calling ShellExecute to launch a document or protocol in its default handler. If the default handler chosen by the user is a Metro style app then this will launch a Metro style app. If the default handler is a desktop app then it will launch a desktop app.
If you are writing a tool such as Visual Studio which needs to activate a specific application directly then the tool can use the ApplicationActivationManager similarly to the following:
#include "targetver.h" #include <Windows.h> #include <ShObjIdl.h> #include <stdio.h> #include <tchar.h> #include <strsafe.h> int _tmain(int argc, _TCHAR* argv[]) { LPCWSTR appId = argv[1]; CoInitialize(NULL); IApplicationActivationManager* paam = NULL; HRESULT hr = E_FAIL; __try { hr = CoCreateInstance(CLSID_ApplicationActivationManager,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&paam)); if (FAILED(hr)) return 0; DWORD pid = 0; hr = paam->ActivateApplication(appId,nullptr,AO_NONE,&pid); if (FAILED(hr)) return 0; wprintf(L"Activated %s with pid %d\r\n",appId,pid); } __finally { if (paam) paam->Release(); } CoUninitialize(); return 0; }
--Rob- Marked As Answer by TanJingdong Tuesday, November 01, 2011 5:04 AM
-
Monday, March 05, 2012 11:18 PM
Hello,
Thanks for the code. Using this, I am able to run a Metro application directly in Desktop through my C++ console application. However when I make my desktop application as a Win32 service an the code attempts to activate the Metro app, I get an error
hr 0x80270253 : Metro style applications can't be activated by Administrator users without a split token.
Any pointers on how this issue can be resolved?
My goal is to have a Win32 service (Desktop mode) that will monitor for a system event and then spawn the Metro app directly into the desktop. Can this be done?
Thanks in Advance.
-
Wednesday, March 28, 2012 5:11 PM
I am too facing the same issue. When tried to activate from a win32 service I get this error: hr 0x80270253 : Metro style applications can't be activated by Administrator users without a split token.
Krj2, were you able to resolve this issue?
-
Wednesday, March 28, 2012 7:43 PM
I also had a similar issue. I suspect some security policy preventing the Metro app to be launched in such a way.
I followed the approach suggested by Rob, and my Win32 application was able to launch Metro applications using IApplicationActivationManager, only if the Win32 application is located somewhere other than C:\Program Files\
If my Win32 application is installed under C:\Program Files\, it failed to launch any Metro app with a return error code:
hr 0x80270254 : This Metro style application does not support the contract specified or is not installed.
Rob, can you shed some lights on the limitations of this approach?
thanks!
-
Wednesday, March 28, 2012 8:48 PM
Yes, i have been able to resolve the issue
Here is what I did:
* Service running in localsystem (default) account
* WTSGetActiveConsoleSessionID
* WTSQueryUserToken
* DuplicateTokenEx
* STARTUPINFO si, set the lpDesktop to winsta0\default
* CreateProcessAsUser (launch a console application)
In the console app, I have the code to activate the metro app:)
- Proposed As Answer by krj2 Wednesday, March 28, 2012 8:51 PM
-
Tuesday, April 10, 2012 4:34 PM
I'm trying to encapsulate this into a dll and run it from a c# WinForm project but it isn't working. The hr i get back from the
hr = paam->ActivateApplication(appId,nullptr,AO_NONE,&pid);
is 0x80270251. I can't find any information on this but I'm guessing the failure has something to do with security. I am trying to run this from Program files like Barry (above) but I've tried outside of Program Files and get the same error.
Questions:
1. Can this be done directly in C#?
2. If not, what do I have to do to make this work as a dll?thanks,
hrp27
- Edited by hrp27 Tuesday, April 10, 2012 7:26 PM
-
Wednesday, April 11, 2012 10:28 AMRob, is there a way to activate an app with the Search contract? I tried to replace the "!App" from the AppId with "!Search" but that resulted in an "unknown contract" error.
-
Friday, April 20, 2012 12:07 PM
Hi Rob,
How can I get the appid of a metro style app? I have tried the packageID but it didn't work!
Thanks!- Edited by poplike110 Friday, April 20, 2012 12:07 PM
-
Friday, August 24, 2012 8:07 PM
Hey Rob,
Could this snippet be open sourced?
Do you mind if I post it as a solution on Github?
Thanks!
-
Thursday, September 13, 2012 10:39 AM
Hi Rob,
Thank you first! I want to do same in C# for UI test. I am new to even C# coding. Please help me.
Thanks!- Edited by Remya P Thursday, September 13, 2012 11:10 AM


