Search code examples
c++visual-studio-2010uwpcreateprocessasuser

Open UWP application from service


I am trying to Launch applications and processes using CreateProcessAsUser from a service I created. My attempts to open applications such as notepad, IE, etc. were successful. But I hit a roadblock when trying to open Groove Music, which is an UWP Application.

When I tried to open Groove Music from Command prompt, the folder was hidden and access was denied.

STARTUPINFO si;
PROCESS_INFORMATION pi;
LPTSTR szCmdline = _tcsdup(TEXT("C:\Program Files\WindowsApps\Microsoft.ZuneMusic_10.18102.10531.0_x64__8wekyb3d8bbwe\Music.UI.exe"));
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
HANDLE t1,t2;
OpenProcessToken(gethandle(_T("explorer.exe")), TOKEN_DUPLICATE | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_PRIVILEGES , &t2);
DuplicateTokenEx(t2, 0, NULL, SecurityImpersonation,TokenPrimary, &t1);
CreateProcessAsUser(t1,NULL,szCmdline,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi)) 

Is there any way to launch UWP applications from a program that I wrote? Or am I missing any apparent methods?


Solution

  • You can do it with the IApplicationActivationManager::ActivateApplication method.

    It needs to be called from a user process, so you'd have to do a two-step approach: From your service call CreateProcessAsUser to create a helper a process, which will then call ActivateApplication.