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

2

2

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.

Holcombe answered 16/1, 2015 at 4:49 Comment(0)
N
8

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).

Noella answered 16/1, 2015 at 5:12 Comment(9)
Thanks for your input. So is there no other way of getting jumplist of any app ? Because i tried IPropertyStore way of getting appUserModelId and then jumpList, but i can't get because most of these applications had not defined explicit userModelId. So this method will not work for me. I want to get jumplist of any application.Holcombe
There is no way to get a jump list without an AppUserModeID, and there is no way to get an AppUserModeID that is implicitly created by Windows (unless you reverse-engineer Windows to figure out the heuristic algorithms it uses to create its implicit AppUserModeIDs).Noella
You don't need an AppID just to run an app. If you know the path to the .exefile, use CreateProcess() or ShellExecute() to run the .exe file directly.Noella
Really? Did you try that? And why do I get an Access Denied when I double click Calculator.exe in Windows 10? In FileExplorer I can't even open the folder "WindowsApps" -> Access Denied even with an Admin account that has read and execute permission. It seems that it is not as simple as you say.Estancia
Yes, it is that simple, and has been that simple for many years. Clearly, you don't have your user account permissions configured correctly if you can't even run the Calculator.Noella
I have read and execute permission. I don't know what should be wrong with that. Apart from that it is no way for me to tell my users that they first must adjust their privileges before my application can programmatically start a StoreApp application! And when I start Calculator.exe from a service with SYSTEM/NT AUTHORITY I get error 193 "%1 is not a valid Win32 application". So your answer does definitely not apply to Windows 10.Estancia
Apart from that it doesn't work on Window 8 neither. If I double click for example WebCam.exe I get the same errors. And the majority of the Store Apps does not have even an EXE file in it's folder. For example in Bing.Sports there are only DLLs and other files but no exe. Conclusion: Store Apps cannot easily be started. The reason is that they run in an application host and not directly.Estancia
You did not say anything earlier about launching Store apps. That is very different than launching standard Win32 apps. See How do I launch a Windows Store application programmatically?Noella
So what you wrote above: "You don't need an AppID just to run an app" is wrong.Estancia
E
0

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

Estancia answered 22/8, 2015 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.