使用 WindowsAPICodePack 在 Win8/64bit 上做一些资源管理器/shell 的工作。在使用 x64 平台目标迭代文件属性时,属性系统出现一些问题会导致 AccessViolationException。似乎是 PropVariant.cs 中的一些问题。切换到 x86 可以解决问题,但会导致目录列表不完整(系统 32/驱动程序中缺少 fe “etc”)。有任何想法吗?
using System;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
namespace ApiCodepackTest
{
class Program
{
const string path = @"c:\windows\system32\drivers";
static void Main(string[] args)
{
var shellObject = (ShellFolder)ShellObject.FromParsingName(path);
showProperties(shellObject);
showItems(shellObject);
Console.ReadLine();
}
static void showProperties(ShellFolder folder)
{
var sys = folder.Properties.System;
foreach (var prop in sys.GetType().GetProperties())
{
try
{
var shellProperty = prop.GetValue(sys) as IShellProperty;
if (shellProperty != null && shellProperty.ValueAsObject != null)
Console.WriteLine(shellProperty.CanonicalName + " " + shellProperty.ValueAsObject);
}
catch{} //you should not pass!
}
}
static void showItems(ShellFolder folder)
{
foreach (var i in folder)
Console.WriteLine(i.Name);
}
}