WindowsAPICodePack を使用して、Win8/64bit でエクスプローラー/シェル処理を行っています。x64 プラットフォーム ターゲットでファイル プロパティを反復処理するときに、プロパティ システムに問題があり、AccessViolationException が発生します。PropVariant.cs に問題があるようです。x86 に切り替えると問題は解決しますが、ディレクトリ リストが不完全になります (system32/drivers に「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);
}
}