Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Icon from UWP App

Tags:

c#

icons

uwp

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.

like image 422
Patrick Avatar asked May 07 '18 15:05

Patrick


People also ask

Is UWP discontinued?

Going forward, UWP will only receive "bug, reliability, and security fixes," and not new features, Microsoft says, indicating that it is now deprecated. Developers with UWP apps in the market who "are happy with [the] current functionality in UWP" can of course continue to keep using UWP.

How do I use UWP app?

To run your UWP app in the simulator, select Simulator from the drop-down list next to the Start Debugging button on the debugger Standard toolbar. This option is only available if your app's Target Platform Min. Version is less than or equal to the operating system on your development machine.

Is UWP a desktop app?

The Universal Windows Platform (UWP) lets you build apps for any Windows device—PCs, Xbox One, HoloLens, and more—and publish them to the Store.

Can UWP apps access registry?

You can't access registry within pure UWP platform directly. However, you can read registry values from a Win32 runFullTrust background process launched from a UWP application, and you can write values in registry from an "elevated" Win32 application launched from that runFullTrust process.


1 Answers

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.

like image 130
Simon Mourier Avatar answered Sep 22 '22 14:09

Simon Mourier