{"id":943,"date":"2020-05-15T23:06:00","date_gmt":"2020-05-15T15:06:00","guid":{"rendered":"http:\/\/blog.5danyuan.com\/?p=943"},"modified":"2020-03-15T23:11:03","modified_gmt":"2020-03-15T15:11:03","slug":"%e6%a0%b9%e6%8d%ae%e8%bf%9b%e7%a8%8b%e8%8e%b7%e5%8f%96-uwp-%e7%9a%84%e5%8c%85%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=943","title":{"rendered":"\u6839\u636e\u8fdb\u7a0b\u83b7\u53d6 UWP \u7684\u5305\u4fe1\u606f"},"content":{"rendered":"\n<p>\u6700\u8fd1\u7684\u4e00\u4e2a\u5b9e\u9a8c\u9879\u76ee\uff0c\u8981\u76d1\u63a7UWP\u7a0b\u5e8f\u7684\u542f\u52a8\u3002\u53d1\u73b0\u4e86\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u4f7f\u7528 WMI\uff0c\u5f53\u6709\u65b0\u7684\u8fdb\u7a0b\u88ab\u521b\u5efa\u65f6\uff0c\u5c31\u53ef\u4ee5\u6536\u5230\u4e00\u4e2a\u6d88\u606f\u56de\u8c03\uff0c\u8fd9\u6837\u7684\u65b9\u5f0f\u6bd4\u4e0d\u65ad\u5730\u53bb\u8f6e\u8be2\u8981\u4f18\u96c5\u548c\u6709\u6548\u7387\u7684\u591a\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u6211\u4eec\u7684\u76ee\u6807UWP\uff0c\u662f\u91c7\u7528 WinJS\u5f00\u53d1\u7684\uff0c\u8fd9\u6837\u4f1a\u5e26\u6765\u4e00\u4e2a\u95ee\u9898\u3002\u5c31\u662f\u5728\u8fdb\u7a0b\u5217\u8868\u91cc\uff0c\u5b83\u662f\u6258\u7ba1\u5728\u4e00\u4e2a\u53eb\u505a wwahost.exe \u7684\u8fdb\u7a0b\u91cc\u7684\u3002\u5982\u679c\u6709\u591a\u4e2a\u7c7b\u4f3c\u7684\u7a0b\u5e8f\u7684\u8bdd\uff0c\u6211\u4eec\u65e0\u6cd5\u7b80\u5355\u5730\u533a\u5206\u51fa\u6765\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8fdb\u4e00\u6b65\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u4ee5\u4fbf\u505a\u8fc7\u6ee4\uff0c\u5e78\u597d\u5fae\u8f6f\u63d0\u4f9b\u4e86\u914d\u5957\u7684\u4e1c\u897f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53eb\u505a UserModelId\u7684\u4e1c\u897f\u6765\u5bf9\u4e0d\u540c\u7684UWP\u7a0b\u5e8f\u505a\u533a\u5206\u3002\u4e0b\u9762\u662f\u6765\u81ea\u5fae\u8f6f\u5b98\u65b9\u7684\u5b9e\u4f8b\u4ee3\u7801\uff08https:\/\/docs.microsoft.com\/zh-cn\/windows\/win32\/api\/appmodel\/nf-appmodel-getapplicationusermodelid\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define _UNICODE 1\n#define UNICODE 1\n\n#include &lt;Windows.h>\n#include &lt;appmodel.h>\n#include &lt;malloc.h>\n#include &lt;stdlib.h>\n#include &lt;stdio.h>\n\nint ShowUsage();\nvoid ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE process);\n\nint ShowUsage()\n{\n    wprintf(L\"Usage: GetApplicationUserModelId &lt;pid> &#91;&lt;pid>...]\\n\");\n    return 1;\n}\n\nint __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv&#91;])\n{\n    if (argc &lt;= 1)\n        return ShowUsage();\n\n    for (int i=1; i&lt;argc; ++i)\n    {\n        UINT32 pid = wcstoul(argv&#91;i], NULL, 10);\n        if (pid > 0)\n        {\n            HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);\n            if (process == NULL)\n                wprintf(L\"Error %d in OpenProcess (pid=%u)\\n\", GetLastError(), pid);\n            else\n            {\n                ShowProcessApplicationUserModelId(pid, process);\n                CloseHandle(process);\n            }\n        }\n    }\n    return 0;\n}\n\nvoid ShowProcessApplicationUserModelId(__in const UINT32 pid, __in HANDLE process)\n{\n    wprintf(L\"Process %u (handle=%p)\\n\", pid, process);\n\n    UINT32 length = 0;\n    LONG rc = GetApplicationUserModelId(process, &amp;length, NULL);\n    if (rc != ERROR_INSUFFICIENT_BUFFER)\n    {\n        if (rc == APPMODEL_ERROR_NO_APPLICATION)\n            wprintf(L\"Desktop application\\n\");\n        else\n            wprintf(L\"Error %d in GetApplicationUserModelId\\n\", rc);\n        return;\n    }\n\n    PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));\n    if (fullName == NULL)\n    {\n        wprintf(L\"Error allocating memory\\n\");\n        return;\n    }\n\n    rc = GetApplicationUserModelId(process, &amp;length, fullName);\n    if (rc != ERROR_SUCCESS)\n        wprintf(L\"Error %d retrieving ApplicationUserModelId\\n\", rc);\n    else\n        wprintf(L\"%s\\n\", fullName);\n\n    free(fullName);\n}<\/code><\/pre>\n\n\n\n<p>\u6574\u4f53\u7684\u4ee3\u7801\u6bd4\u8f83\u7b80\u5355\uff0c\u6ca1\u6709\u4ec0\u4e48\u7279\u522b\u597d\u8bf4\u7684\u3002\u4ee3\u7801\u4e2d\u4e00\u5171\u8c03\u7528\u4e862\u6b21GetApplicationUserModelId\u65b9\u6cd5\uff0c\u7b2c\u4e00\u6b21\u662f\u4e3a\u4e86\u8ba1\u7b97\u6570\u636e\u7684\u957f\u5ea6\uff0c\u7136\u540e\u7b2c\u4e8c\u6b21\u6839\u636e\u6570\u636e\u957f\u5ea6\u91cd\u65b0\u8bf7\u6c42\u4ee5\u5f97\u5230\u6700\u7ec8\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u8fd9\u5c31\u662f\u6211\u4e3a\u4ec0\u4e48\u8ba8\u538cC++\u7684\u539f\u56e0\uff0c\u628a\u6307\u9488\u7684\u64cd\u4f5c\u641e\u8fd9\u4e48\u6076\u5fc3\u3002<\/p>\n\n\n\n<p>\u5728\u4ee3\u7801\u9a8c\u8bc1\u540e\uff0c\u53c8\u53d1\u73b0\u4e86\u53e6\u5916\u4e00\u4e2aAPI\uff1aIsImmersiveProcess \uff0c\u901a\u8fc7\u8be5\u51fd\u6570\u53ef\u4ee5\u7b80\u5355\u5730\u5224\u65ad\u4e00\u4e2a\u8fdb\u7a0b\u662f\u5426\u662fStore\u7c7b\u578b\u7684\u7a0b\u5e8f\uff0c\u5728\u6709\u7684\u573a\u5408\u4f8b\u5982\u552f\u4e00\u6027\u6821\u9a8c\u4e0a\u8fd8\u662f\u6709\u5e2e\u52a9\u7684\u3002\u6709\u5174\u8da3\u53ef\u4ee5\u79fb\u6b65 https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/winuser\/nf-winuser-isimmersiveprocess<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u7684\u4e00\u4e2a\u5b9e\u9a8c\u9879\u76ee\uff0c\u8981\u76d1\u63a7UWP\u7a0b\u5e8f\u7684\u542f\u52a8\u3002\u53d1\u73b0\u4e86\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u4f7f\u7528 WMI\uff0c\u5f53\u6709\u65b0\u7684\u8fdb\u7a0b\u88ab\u521b\u5efa\u65f6\uff0c\u5c31\u53ef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[234,3,5],"tags":[316,277,317],"class_list":["post-943","post","type-post","status-publish","format-standard","hentry","category-c","category-a-short-word","category-daily","tag-c-2","tag-uwp","tag-317"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=943"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/943\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}