VBScript to Pin or UnPin items to the Start Menu (Windows 10)

Executable files on the local machine may be Pinned to the Start Menu and/or Taskbar.

PIN.vbs

Dim strFolder, strExecutable

strFolder = "C:\Windows\System32\"
strExecutable = "notepad.exe"

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strFolder)
Set objFolderItem = objFolder.ParseName(strExecutable)

Set colVerbs = objFolderItem.Verbs

'uncomment this section to display the available verbs
' For Each objVerb In colVerbs
'    If objVerb <> "" Then
'       WScript.Echo objVerb
'    End If
' Next

'Loop through the verbs and if PIN is found then 'DoIt' (execute)
blnOptionFound = False
For Each objVerb In colVerbs
   If Replace(objVerb.name, "&", "") = "Pin to Start" Then
      objVerb.DoIt
      blnOptionFound = True
      WScript.Echo "The application '" & strExecutable & "' was just Pinned to the Start Menu."
   End If
Next

if blnOptionFound = false then
   WScript.Echo "The application '" & strExecutable & "' failed to pin to the Start Menu (may already be present)."
end if

Items can also be pinned to the TaskBar instead of the Start menu, replace 'Pin to Start' with 'Pin to Taskbar'.

To remove items use the UNPIN script below:

UNPIN.vbs

Dim strFolder, strExecutable

strFolder = "C:\Windows\System32\"
strExecutable = "notepad.exe"

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strFolder)
Set objFolderItem = objFolder.ParseName(strExecutable)

'Collect Applications verbs
Set colVerbs = objFolderItem.Verbs

'Loop through the verbs and if UNPIN is found then 'DoIt' (execute)
blnOptionFound = False
For Each objVerb In colVerbs
   If Replace(objVerb.name, "&", "") = "Unpin from Start" Then
      objVerb.DoIt
      blnOptionFound = True
      WScript.Echo "The application '" & strExecutable & "' was just Unpinned from the Start Menu."
   End If
Next

if blnOptionFound = false then
   WScript.Echo "The application '" & strExecutable & "' failed to be unpinned from the Start Menu (may not be present)."
end if

The reason we replace the ampersands in the script above is that the Verb names include keyboard shortcuts like “P&in to Start”, these are not always visible in the UI, so the script strips out all ampersands before performing the comparison.

What can be Pinned?

In addition to executable programs you can pin many other things to the Start Menu or Taskbar:

For some of these the easiest way to Pin them from the command line is to first create a shortcut to the item and then pin the shortcut.

When using the GUI, holding the shift key when calling up a context menu against a file on the local hard drive will reveal an option for Pin to Start menu, even for non-executable files (.exe and .lnk).

Internet Explorer 11 Pinned sites

The script above will Pin a SHORTCUT to the start Menu, this should not be confused with an IE Pinned Site (.website) link.

If you drag a URL/Icon from the address bar of IE 11 to the desktop, that will create an IE Pinned site.

"Pinned sites" are designed specifically to only ever open in IE 11, you should use them for legacy systems containing Active-X controls or other cruft that won't work in Microsoft Edge.

“It is not the place for a program to decide unilaterally, 'I am so cool. I am your favorite icon. I just know it'” ~ The Old New Thing

Related

MapDrive - Map a Drive letter to a network file share
qchange - Re-assign network printer connections
PowerShell - Pin / Unpin applications from the taskbar and Start menu.


 
Copyright © SS64.com 1999-2019
Some rights reserved