Created
September 13, 2016 20:48
-
-
Save Alia5/282f5e8cb859220669d7c2682653e0e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Windows.h> | |
#include <atlbase.h> | |
#include <Shobjidl.h> | |
#include <appmodel.h> | |
#include <AppxPackaging.h> | |
#include <string> | |
HRESULT LaunchApplication(LPCWSTR packageFullName, PDWORD pdwProcessId) | |
{ | |
CComPtr<IApplicationActivationManager> spAppActivationManager; | |
HRESULT result = E_INVALIDARG; | |
// Initialize IApplicationActivationManager | |
result = CoCreateInstance(CLSID_ApplicationActivationManager, NULL, CLSCTX_LOCAL_SERVER, IID_IApplicationActivationManager, (LPVOID*)&spAppActivationManager); | |
if (!SUCCEEDED(result)) | |
return result; | |
// This call ensures that the app is launched as the foreground window | |
result = CoAllowSetForegroundWindow(spAppActivationManager, NULL); | |
if (!SUCCEEDED(result)) | |
return result; | |
// Launch the app | |
result = spAppActivationManager->ActivateApplication(packageFullName, NULL, AO_NONE, pdwProcessId); | |
return result; | |
} | |
int main() | |
{ | |
DWORD pid = 0; | |
std::wstring name = L"Microsoft.ApexPG_8wekyb3d8bbwe!forzamotorsportapex"; //AppUserModelID | |
HRESULT hr = CoInitialize(nullptr); | |
if (SUCCEEDED(hr)) { | |
HRESULT result = LaunchApplication(name.c_str(), &pid); | |
std::cout << "result: " << result << "; pid: "; | |
} | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment