C# 編輯 Windows 快速存取清單

加入參考 Microsoft Shell Controls and Automation

新增快速存取

Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shellAppType);
Shell32.Folder2 f = (Shell32.Folder2)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { "folderPath" });
f.Self.InvokeVerb("pintohome");

即會將 folderPath 的資料夾加入快速存取

刪除快速存取

Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shellAppType);
Shell32.Folder2 f2 = (Shell32.Folder2)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { "shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}" });
Console.WriteLine("item count: " + f2.Items().Count);
foreach (FolderItem fi in f2.Items())
{
    Console.WriteLine(fi.Name);
    if (fi.Name == "folderName")
    {
        ((FolderItem)fi).InvokeVerb("unpinfromhome");
    }
}

即會將 folderName 從快速存取移除

完整程式碼範例

發佈留言