Get Icon from UWP App

▼魔方 西西 提交于 2019-12-12 07:51:26

问题


I want to extract the icon of an UWP App to build a Explorer like "Open With" menue.

With the help of SHAssocEnumHandlers i managed to get the associated applications to a given file extension.

With IAssocHandler::GetIconLocation i get for UWP Apps (Microsoft Edge) something like:

@{Microsoft.MicrosoftEdge_41.16299.371.0_neutral__8wekyb3d8bbwe?ms-resource://Microsoft.MicrosoftEdge/Files/Assets/MicrosoftEdgeSquare44x44.png}

If i use SHLoadIndirectString on this string i get:

C:\WINDOWS\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\Assets\MicrosoftEdgeSquare44x44.scale-100.png

But that is the wrong Icon (has no color or contrast).

In the directory:

C:\WINDOWS\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\Assets\

Are a lot of different Images. I don't understand how to choose the correct icon.

I tried to look up the "AppxManifest.xml" but i looks completly different for different Apps.

For an non UWP App i get as IconLocation something like:

C:\WINDOWS\system32\NOTEPAD.EXE

Then i can use:

Icon.ExtractAssociatedIcon()

and everything is fine. I didn't finde any way to do the same with an UWP App.


回答1:


UWP apps (or Windows Store apps, or apps in what's called sometimes the "AppX application model") information can be queried from official APIs.

These APIs don't have a C# equivalent AFAIK but I've provided sample code to do this in my answer to a similar question here on SO: Getting icon of “modern” Windows app from a desktop application?

The sample application dumps all current loaded Windows Store packages & apps.

Note there is not just one icon for a UWP app, there may be many, to be able to adapt to a specific device, form factors, etc. The sample code has a utility that gets the highest scale image for a given resource.




回答2:


For me the following method works:

  1. Open File Explorer and type C:/Program Files/WindowsApps in the adress bar.
  2. In the You dont' have permission to access this folder dialog click Continue. This will require administrator privilages.
  3. In the You have been denied permission to this folder dialog click security tab highlighted in blue.
  4. In the WindowsApps Properties dialog click Advanced.
  5. In the Advanced Security Settings for WindowsApps dialog click Continue.
  6. Click the blue text Change next to Owner: TrustedInstaller.
  7. In the Enter object name to select textbox in the Select an object or group dialog enter your username (the one displayed in cmd after C:/User/ right after opening it).
  8. Click the Check Names button.
  9. Click the OK button.
  10. In the Advanced Security Settings for WindowsApps dialog click Apply and then OK.
  11. Close File Explorer.
  12. Reopen File Explorer and type C:/Program Files/WindowsApps in the adress bar again.

Now you will see a list of folders. Each corresponds to a UWP app installed on your computer. Some apps are in multiple folders. App's resources are places in the /Assets subfolder. You will find there the app's icon too.




回答3:


I think you have to combine both,

first check AppxManifest.xml and search for uap:VisualElements block,

then find Square150x150Logo key in it,

then get the related value and find the file in the given address and use it.



来源:https://stackoverflow.com/questions/50217328/get-icon-from-uwp-app

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