How to get appUserModelId for any app in windows 7/8 using vc++

浪子不回头ぞ 提交于 2019-12-13 00:37:08

问题


I want to find out recent/frequent items from jumplist of any app. I know that we can do this using IApplicationDocumentLists interface. But we need appUserModelId for that. So now my problem is to find out appUserModelId for any app, given its exe path. Any help will be highly appreciated.


回答1:


AppUserModeIDs are not part of the EXE file itself, so it is not enough to just have the path to the EXE file. AppUserModeIDs are assigned while the EXE is running, and they can be assigned on process-wide or per-window basis.

To query a process's explicit AppUserModeID, you would have to inject code into that process and have it call GetCurrentProcessExplicitAppUserModelID(), then use an IPC mechanism to send the value back to your main app.

To query a window's explicit AppUserModeID, you can use SHGetPropertyStoreForWindow() to get the window's IPropertyStore interface, and then call IPropertyStore.GetValue() specifying PKEY_AppUserModel_ID as the property key.

Note that in either case, these functions only work for explicit AppUserModeIDs. They do not work for implicit AppUserModeIDs that are assigned by Windows if an app does not assign an explicit AppUserModeID for itself. This is clearly stated in the documentation:

Application User Model IDs (AppUserModelIDs)

Some applications do not declare an explicit AppUserModelID. They are optional. In that case, the system uses a series of heuristics to assign an internal AppUserModelID. However, there is a performance benefit in avoiding those calculations and an explicit AppUserModelID is the only way to guarantee an exact user experience. Therefore, it is strongly recommended that an explicit ID be set. Applications cannot retrieve a system-assigned AppUserModelID.

Update: in Windows 8, Microsoft added a new GetApplicationUserModelId() function:

Gets the application user model ID for the specified process.

You can use that instead of injecting code to call GetCurrentProcessExplicitAppUserModelID(). I have not tried it yet, but I suspect it returns the current AppUserModeID regardless of how it is assigned (explicit or system-assigned).




回答2:


You cannot obtain the AppUserModelId from the Exe path. This is not possible.

But you can read my posting how to enumerate all AppUserModelId's of all installed StoreApps for the current user: How to enumerate the installed StoreApps and their ID in Windows 8 and 10



来源:https://stackoverflow.com/questions/27977474/how-to-get-appusermodelid-for-any-app-in-windows-7-8-using-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!