Today I’ve been solving interesting task. All my investigation I’ll write on this article. A problem is following: there is a regular C# application which should display all installed WinRT application per user.
There is a whole section of all WinRT APIs for Windows 8 that are able to be called from a regular C# application on MSDN. This one includes a PackageManager class which allows getting all installed packages.
Access WinRT API from Console application.
First step, create a usual Console application.
Then we need reference a Window.dll. However, in the desktop projects Windows tab doesn’t appear by default. For this we need manually add following lines to csproj file.
After that step a new tab will appear:
Now we can try to get all WinRT installed packages. However, when we build that we will have following error:
The type ‘System.Collections.Generic.IEnumerable`1<T0>’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.
Unfortunately this assembly doesn’t present on reference tab. For this you need add this assembly from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5 folder.
Get all installed WinRT application per user.
We will get installed Metro/Modern packages per user because on same computer different users can install different applications. All this information is available by PackageManager class.
var packageManager = new PackageManager(); var metroApps = packageManager.FindPackagesForUser(WindowsIdentity.GetCurrent().User.Value);
That’s all and really simple, isn’t it? 😉