如何用命令行啟動Metro App?
或者具體說是Metro的OneNote。
是這樣,我有台X200t升級到Win 10了,原來使用的是桌面版本的OneNote,現在想改成使用Metro版的OneNote。Tablet PC嘛,自然有物理的平板電腦按鍵,這幾個按鍵可以設置成啟動一個應用。原來我是把其中一個按鍵啟動桌面版的OneNote,但我不知道要怎麼用命令行啟動Metro App,煩請賜教。--------------------------------------- G+上的一位網友提出了一個曲線辦法
先把onenote釘在開始菜單,把他拖到桌面,給一個快捷鍵(我用了Ctrl+Shift+F12這麼獵奇的應該沒其他應用會用到吧),Tablet按鈕也設置成按這個快捷鍵。
摘自 Automating the testing of Windows 8 appsAutomating the activation of your app使用下面的代碼
#include "stdafx.h"
#include &
#include &
#include &
#include &
#include &
#include &
/*++
Routine Description:
This routine launches your app using IApplicationActivationManager.
Arguments:
strAppUserModelID - AppUserModelID of the app to launch.
pdwProcessId - Output argument that receives the process id of the launched app.
Return value:
HRESULT indicating success/failure
--*/
HRESULT LaunchApp(const std::wstring strAppUserModelId, PDWORD pdwProcessId)
{
CComPtr&
HRESULT hrResult = E_INVALIDARG;
if (!strAppUserModelId.empty())
{
// Instantiate IApplicationActivationManager
hrResult = CoCreateInstance(CLSID_ApplicationActivationManager,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IApplicationActivationManager,
(LPVOID*)spAppActivationManager);
if (SUCCEEDED(hrResult))
{
// This call ensures that the app is launched as the foreground window
hrResult = CoAllowSetForegroundWindow(spAppActivationManager, NULL);
// Launch the app
if (SUCCEEDED(hrResult))
{
hrResult = spAppActivationManager-&>ActivateApplication(strAppUserModelId.c_str(),
NULL,
AO_NONE,
pdwProcessId);
}
}
}
return hrResult;
}
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hrResult = S_OK;
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
{
if (argc == 2)
{
DWORD dwProcessId = 0;
++argv;
hrResult = LaunchApp(*argv, dwProcessId);
}
else
{
hrResult = E_INVALIDARG;
}
CoUninitialize();
}
return hrResult;
}
C:&>Win8AppLaunch.exe Microsoft.BingNews_8wekyb3d8bbwe!AppexNews
$installedapps = get-AppxPackage
foreach ($app in $installedapps)
{
foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id)
{
$app.packagefamilyname + "!" + $id
}
}
Opening Windows 8 Apps from a Command Prompt or Script
http://stackoverflow.com/questions/26244759/opening-a-file-in-a-metro-app-from-command-line更新一下,之前說的不嚴謹。
如果不是在cmd下輸命令運行,則應該是 cmd /c "start 包名"比如啟動應用商店則是:cmd /c "start ms-windows-store:"
Windows 10 RTM實測可用。Win8應該也可以。
參考:Opening Windows 8 Apps from a Command Prompt or Script我記得商店應用是安裝在用戶目錄裡面的,也是EXE,具體怎麼啟動晚上回去試試。
實驗過了,不能直接運行metro應用的exe,需要容器上下文。還是用別人說的那個start程序來啟動吧。。。推薦閱讀:
※win10 今天更新完,就打不開開始菜單,下面工具欄所有都沒有反應?
※win10開始菜單的磁貼怎麼擺放比較好看?
※為什麼我的windows 10 無法正常運行了(開始菜單不出現,顯示選項無法打開)?
TAG:微軟Microsoft | MicrosoftWindows | MicrosoftOneNote | MetroApp | Windows10 |