Is it possible programmatically add folders to the Windows 10 Quick Access panel in the explorer window?

前端 未结 9 919
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 12:18

Apparently Microsoft has (sort of) replaced the \"Favorites\" Windows explorer item with the Quick Access item. But I haven\'t been able to find a way to programmatically ad

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 12:33

    I was able to get this to work in C# using shell32 based on the information in this post and some info on shell32 from this post https://stackoverflow.com/a/19035049

    You need to add a reference to "Microsoft Shell Controls and Automation".

    This will add a link

    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[] { "C:\\temp" });
    f.Self.InvokeVerb("pintohome");
    

    This will remove a link by name

    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 == "temp")
        {
            ((FolderItem)fi).InvokeVerb("unpinfromhome");
        }
    }
    

提交回复
热议问题