Finding out installed Metro applications on a machine
Asked Answered
S

4

6

I am trying to write a piece of code in C# to find all installed Metro Applications on a machine. I came across the following post Get a list of metro apps and launch them in Windows 8 using PowerShell which explains obtaining this from the system registry. Is this the only reliable way to obtain the list? Does anyone know of any other ways? Thanks in advance

Synovitis answered 12/8, 2013 at 3:0 Comment(1)
Are you looking for a way to do this from within a Metro application itself? Because if so, it feels like the sort of thing that wouldn't be possible when running within the sandboxed environment.Attenuation
M
4

I wish I could comment...Is this an option?

IEnumerable<Windows.ApplicationModel.Package> packages = 
        (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser("");

http://msdn.microsoft.com/en-us/library/windows/apps/windows.management.deployment.packagemanager.aspx

Moffitt answered 12/8, 2013 at 4:49 Comment(3)
The above code is not working for Windows 8 app, it's throwing "Access is denied" exception, while initializing PackageManager object. It will work only in desktop or console app.Spot
My bad, clearly says "You can not use this class in a Windows Store app."Moffitt
I get the following error when I compile the project "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=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'" . Any ideas why I am seeing this?Synovitis
S
7

Thanks everyone! For the PackageManager code to work, I had to do the following

1) Add the following to .csproj.

 <PropertyGroup>
   <TargetPlatformVersion>8.0</TargetPlatformVersion>
 </PropertyGroup>
 <Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

2) Add a reference to C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd

After doing the above, I was able to list all the metro packages.

Synovitis answered 13/8, 2013 at 16:9 Comment(3)
So eventually did it work inside a metro App or you were able to iterate the in a non-metro App?Moffitt
I was getting Yam's error in the comment to Braim's answer above, but added <Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> to the .csproj file inside the <ItemGroup> tags. This fixed the error and the project built successfully. The project is a console app.Lapse
Thanks! On my computer, the reference in step 2 was at C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Annotated\Windows.winmd.Succuss
M
4

I wish I could comment...Is this an option?

IEnumerable<Windows.ApplicationModel.Package> packages = 
        (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser("");

http://msdn.microsoft.com/en-us/library/windows/apps/windows.management.deployment.packagemanager.aspx

Moffitt answered 12/8, 2013 at 4:49 Comment(3)
The above code is not working for Windows 8 app, it's throwing "Access is denied" exception, while initializing PackageManager object. It will work only in desktop or console app.Spot
My bad, clearly says "You can not use this class in a Windows Store app."Moffitt
I get the following error when I compile the project "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=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'" . Any ideas why I am seeing this?Synovitis
S
1

You can't iterate through all packages installed in PC in WinRT app. It's possible in desktop and console app. See these MSDN threads for more info.

How to get all Metro apps list in Metro App?

How do I get all Metro style apps list in my Metro App?

To perform the same here's code.

Spot answered 12/8, 2013 at 6:33 Comment(0)
T
0

If anyone's wondering how to get the packageManager variable in the accepted answer you need to do the following:

Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

I guess this belongs to a comment, but I don't have enough reputation, sorry.

Tetrabrach answered 7/7, 2019 at 19:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.