【发布时间】:2018-09-10 07:12:46
【问题描述】:
我可以使用 DriveInfo.GetDrives() 方法列出本地磁盘。另外,我使用 Name 属性访问/获取驱动器名称。但我收到错误为“系统。未授权访问异常:'访问路径'X:\'被拒绝。”在访问诸如 AvailableFreeSpace 之类的任何属性时。代码如下。
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Debug.WriteLine("Drive: " + d.Name); //This line executes w/o error!
Debug.WriteLine("Drive: " + d.AvailableFreeSpace);
Debug.WriteLine("Drive: " + d.TotalSize);
}
注意:我在包标签块中放置了以下行 xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 和
【问题讨论】: