When getting the packages for my user i am getting "The system cannot find the file specified" in some InstalledLocation. Anyone knows why this happens? Are this apps broken? I need to get the InstalledLocation, is there anyway that i can do this without the try catch block? Thanks in advance
using System;
using System.IO;
using System.Security.Principal;
using Windows.Management.Deployment;
namespace ConsoleApp19
{
class Program
{
static void Main(string[] args)
{
NTAccount acc = new NTAccount(WindowsIdentity.GetCurrent().Name);
SecurityIdentifier sid = (SecurityIdentifier)acc.Translate(typeof(SecurityIdentifier));
var packages = new PackageManager().FindPackagesForUser(sid.ToString());
foreach (var package in packages)
{
Console.WriteLine(package.Id.FamilyName);
try
{
Console.WriteLine(package.InstalledLocation.Path);
}
catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
}
Console.ReadKey();
}
}
}
Some apps that are installed in development mode throw error on acessing to installedLocation. To avoid this just check if they ate in development mode
if (!package.IsDevelopmentMode)
{
}
User contributions licensed under CC BY-SA 3.0