【问题标题】:Package Manager > The system cannot find the file specified. (Exception from HRESULT: 0x80070002)包管理器 > 系统找不到指定的文件。 (来自 HRESULT 的异常:0x80070002)
【发布时间】:2019-05-20 12:47:36
【问题描述】:

为我的用户获取软件包时,我在某些 InstalledLocation 中收到“系统找不到指定的文件”。有谁知道为什么会这样?这个应用程序坏了吗?我需要获取 InstalledLocation,无论如何我可以在没有 try catch 块的情况下执行此操作吗?提前致谢

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://docs.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findpackagesforuser

【问题讨论】:

  • 您在访问 InstalledLocation 之前检查过 package.Status 吗?对于那些无法访问的,它会返回什么?
  • @StefanWickMSFT 对于我所有的包,package.Status 中的所有属性(DataOffiline、DependencyIssue 等)都是错误的。

标签: c# .net windows uwp


【解决方案1】:

在开发模式下安装的某些应用程序在访问 installedLocation 时会抛出错误。为了避免这种情况,只需检查他们是否在开发模式下进食

if (!package.IsDevelopmentMode)
{
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    相关资源
    最近更新 更多