Can I Pin a File to the Start Menu by Using a Script?

Can I Pin a File to the Start Menu by Using a Script?

  • Comments 7
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! Can I pin a file to the Start Menu by using a script?

-- ZD

SpacerHey, Scripting Guy! AnswerScript Center

Hey, ZD. For those of you who haven’t bought Windows XP yet (hey, what’s the matter with you; we Scripting Guys have families to feed!), by default XP’s Start Menu changes over time: the more you use an application, the more likely it is to appear on the Start Menu. The less you use an application - well, use it or lose, huh? (Incidentally, this refers solely to the application shortcuts that appear when you first click the Start button. Shortcuts that show you up when you click All Programs stay put, and don’t appear or disappear depending on use.)

Most of the time this works out pretty good; after all, the applications you use most often are probably the applications you use most often. However, there might be an application or two that you always want to appear on the Start menu even if you don’t use the program all that often. In that case you can “pin” the item to the Start menu; once pinned, the application will stay on the Start menu forever (or until you unpin it), even if you never use the application.

In Windows Explorer, you can pin an application to the Start Menu by right-clicking the application icon and then clicking Pin to Start Menu. Nothing wrong with that, of course, but if want to really be cool you can pin items to the Start Menu using a script. Here, for example, is a script that pins the Windows Calculator (calc.exe) to the Start Menu:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Windows\System32")
Set objFolderItem = objFolder.ParseName("calc.exe")

objFolderItem.InvokeVerb("P&in to Start Menu")

As you can see, we use the Shell Application object in order to perform this task. After creating an instance of the Shell object, we use the Namespace method to bind to the folder (C:\Windows\System32) where Calculator resides. We then use the ParseName method to bind to the actual executable file (calc.exe).

Why can’t we just bind directly to the file? Who knows; that’s just the way the Shell object is designed. But hey, it’s just one extra line of code, and the net result is the same: we get hooked up to C:\Windows\System32\Calc.exe.

After that we use the InvokeVerb method to pin the application to the Start Menu. Verbs are items that appear on the context menu when you right-click the application icon in Windows Explorer. And that’s not a misprint in P&in to Start Menu; the ampersand is part of the command name, and indicates the shortcut key for the item (in this case, the letter i). It looks weird, but it has to be there.

Ok, ok, how did we know the ampersand has to be there? Simple: we ran this script, which returns a list of verbs that can be applied to Calc.exe:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Documents and Settings\gstemp\Desktop\Stuff")
Set objFolderItem = objFolder.ParseName("bob.vbs")
 
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
    Wscript.Echo objVerb
Next

And, yes, these verbs are pretty cool, although they aren’t as cool as you might expect. That’s because when you invoke a verb, that verb functions exactly the same as if you had chosen the item from the context menu. For example, if you right-click a file and choose Delete, a dialog box pops up asking if you want to send the file to the Recycle Bin. The same thing happens if you call the Delete method programmatically; instead of automatically deleting the file, that same confirmation box appears. Give this script a try, and you’ll see what we mean:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Windows\System32")
Set objFolderItem = objFolder.ParseName("calc.exe")

objFolderItem.InvokeVerb("&Delete")

Still, something worth playing around with.

And before you ask, the answer is yes: you can also unpin an item from the Start Menu by using a script:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Windows\System32")
Set objFolderItem = objFolder.ParseName("calc.exe")

objFolderItem.InvokeVerb("Unp&in from Start Menu")

Could life get any better?


Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • solo4everz.wordpress.com

    how to make exe file for free?

  • Thanks Alot dear ,

    it works for me.

    thank you so much for helping me .

  • We are deploying Office 2010 to Windows XP clients that have Office 2007 links pinned. Since the file no longer exists where these Office 2007 files were located this method fails. How can we unpin items that are dead links?

    Thanks for the tutorial otherwise.

  • Is it possible to pin any file to start menu using vbscript? for example cmd or bat stc.

  • See this script for pinning and unpinning from taskbar and start menu

    gallery.technet.microsoft.com/.../b66434f1-4b3f-4a94-8dc3-e406eb30b750

  • How could I pin a folder to start Menu

  • The unpin item from Start Menu doesn't work for me, it doesn't generate an error

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.NameSpace(strAllUsersProgramsPath & "\Cisco\Cisco AnyConnect Secure Mobility Client")
    Set objFolderItem = objFolder.ParseName("Cisco AnyConnect Secure Mobility Client.lnk")
    objFolderItem.InvokeVerb("Unpin from Start Men&u")

    if checked the verb & it is correct for this shortcut.lnk

    Any Ideas ?