1

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();
        }
    }
}

https://learn.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackagesforuser

2
  • Have you checked package.Status before accessing the InstalledLocation? What does it return for those that can't be accessed? Commented Dec 20, 2018 at 1:14
  • @StefanWickMSFT for all my packages all the properties (DataOffiline, DependencyIssue, etc) in package.Status are false. Commented Dec 20, 2018 at 1:19

1 Answer 1

0

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)
{
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.