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

前端 未结 9 860
爱一瞬间的悲伤
爱一瞬间的悲伤 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:25

    Maybe it will help someone until MS releases an API. I ran procmon and it seems that these registry keys are involved

    Pin to Quick access:

    HKEY_CLASSES_ROOT\Folder\shell\pintohome
    

    When unpin:

    HKEY_CLASSES_ROOT\PinnedFrequentPlace\shell\unpinfromhome\command
    

    Also this resource is used when pinning: (EDIT1: can't find it any longer..)

    AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\{SOME_SORT_OF_GUID}.automaticDestinations-ms
    

    You can try opening it with 7-zip, there are several files in there which fit the destination

    EDIT2: I found running this in the 'Run' opens up Quick access:

    shell:::{679F85CB-0220-4080-B29B-5540CC05AAB6}
    
    0 讨论(0)
  • 2020-11-28 12:25
    void PinToHome(const std::wstring& folder)
    {
        ShellExecute(0, L"pintohome", folder.c_str(), L"", L"", SW_HIDE);
    }
    

    that was the easy part, still unable to do an unpinfromhome

    0 讨论(0)
  • 2020-11-28 12:26

    Yohan Ney's answer for pinning an item is correct. To unpin an item you can do this:

    $QuickAccess = New-Object -ComObject shell.application 
    ($QuickAccess.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where {$_.Path -eq "C:\Temp"}).InvokeVerb("unpinfromhome")
    

    Here's a script I wrote to make pin/unpin a little easier:

    https://gallery.technet.microsoft.com/Set-QuickAccess-117e9a89

    0 讨论(0)
  • 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");
        }
    }
    
    0 讨论(0)
  • 2020-11-28 12:34

    I like Johan's answer but I added a little bit to make not remove some of the items that were already in there. I had a ton pinned in there by accident I must have selected pin folder or something to quick access.

    $QuickAccess = New-Object -ComObject shell.application 
    $okItems = @("Desktop","Downloads","Documents","Pictures","iCloud Photos","iCloud Drive","PhpstormProjects","Wallpapers 5","Videos", "Schedules for testing")
    ($QuickAccess.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where {$_.name -notin $okItems}).InvokeVerb("unpinfromhome");
    
    0 讨论(0)
  • 2020-11-28 12:35

    Building on what others have said... This allows you to remove all pinned folders (not just all/recent folders/items):

    $o = new-object -com shell.application
    $($o.Namespace("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}").Items() | where { $_.IsFolder -eq "True" -and ($($_.Verbs() | Where-Object {$_.Name -in "Unpin from Quick access"}) -ne $null)}).InvokeVerb("unpinfromhome")
    

    I needed this so I could backup / restore my list of Quick Access links quickly. So I put this at the top of my script (to remove all pinned items, then the rest of the script re-adds them. This ensures the order is correct.

    And yes, I'm sure there's a better syntax for the above code.

    0 讨论(0)
提交回复
热议问题