Search code examples
vbscriptwindows-10windows-11

Is it possible programmatically add folders to the Windows 10/11 Quick Access panel in Explorer?


I want to use VBScript to programmatically add folders to the Windows 10/11 Quick Access toolbar in Explorer.

This works well in PowerShell:

$QuickAccess = New-Object -ComObject shell.application;
$PathToPin = '\\Folder';
if(-not ($QuickAccess.Namespace('shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}').Items() | ? {$_.Path -eq $PathToPin})){$QuickAccess.Namespace($PathToPin).Self.InvokeVerb('pintohome')}

There is a similar question, but I need VBScript.

I tried to do it like this:

Set PathToPin = CreateObject("\\192.168.0.20\Folder100")
Set qa = CreateObject("Shell.Application")
qa.NameSpace(PathToPin).Self.InvokeVerb("pintohome")

But I get an error:

Microsoft VBScript runtime error: Object required: 'qa.NameSpace(...)'

Any idea on how to fix this?


Solution

  • Set PathToPin = CreateObject("\\192.168.0.20\Folder100")
    

    This is just plain wrong. For one thing, that is not a valid COM object designation, so CreateObject() will fail, hence the error you are getting when you try to use that object afterwards. For another thing, the Shell.Namespace() method expects a file path string, not a COM object.

    Try this instead:

    Dim PathToPin
    PathToPin = "\\192.168.0.20\Folder100"
    Set qa = CreateObject("Shell.Application")
    qa.NameSpace(PathToPin).Self.InvokeVerb("pintohome")
    

    I tested it and it works. But, I tested using a local folder, not a UNC folder. Hopefully it will work with a UNC folder, too.