{"id":71023,"date":"2004-11-11T17:45:00","date_gmt":"2004-11-11T17:45:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/11\/11\/can-i-pin-a-file-to-the-start-menu-by-using-a-script\/"},"modified":"2004-11-11T17:45:00","modified_gmt":"2004-11-11T17:45:00","slug":"can-i-pin-a-file-to-the-start-menu-by-using-a-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/can-i-pin-a-file-to-the-start-menu-by-using-a-script\/","title":{"rendered":"Can I Pin a File to the Start Menu by Using a Script?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! Can I pin a file to the Start Menu by using a script?<BR><BR>&#8212; ZD<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, ZD. For those of you who haven\u2019t bought Windows XP yet (hey, what\u2019s the matter with you; we Scripting Guys have families to feed!), by default XP\u2019s 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 &#8211; well, use it or lose, huh? (Incidentally, this refers solely to the application shortcuts that appear when you first click the <B>Start<\/B> button. Shortcuts that show you up when you click <B>All Programs<\/B> stay put, and don\u2019t appear or disappear depending on use.)<\/P>\n<P>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 <I>always<\/I> want to appear on the Start menu even if you don\u2019t use the program all that often. In that case you can \u201cpin\u201d 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.<\/P>\n<P>In Windows Explorer, you can pin an application to the Start Menu by right-clicking the application icon and then clicking <B>Pin to Start Menu<\/B>. Nothing wrong with that, of course, but if want to <I>really<\/I> be cool you can pin items to the Start Menu using a script. Here, for example, is a script that pins the Windows Calculator (<B>calc.exe<\/B>) to the Start Menu:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(&#8220;C:\\Windows\\System32&#8221;)\nSet objFolderItem = objFolder.ParseName(&#8220;calc.exe&#8221;)<\/p>\n<p>objFolderItem.InvokeVerb(&#8220;P&amp;in to Start Menu&#8221;)\n<\/PRE>\n<P>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 (<B>C:\\Windows\\System32<\/B>) where Calculator resides. We then use the ParseName method to bind to the actual executable file (<B>calc.exe<\/B>).<\/P>\n<P>Why can\u2019t we just bind directly to the file? Who knows; that\u2019s just the way the Shell object is designed. But hey, it\u2019s just one extra line of code, and the net result is the same: we get hooked up to C:\\Windows\\System32\\Calc.exe.<\/P>\n<P>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\u2019s not a misprint in <B>P&amp;in to Start Menu<\/B>; the ampersand is part of the command name, and indicates the shortcut key for the item (in this case, the letter <I>i<\/I>). It looks weird, but it has to be there.<\/P>\n<P>Ok, ok, how did we <I>know<\/I> the ampersand has to be there? Simple: we ran this script, which returns a list of verbs that can be applied to Calc.exe:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(&#8220;C:\\Documents and Settings\\gstemp\\Desktop\\Stuff&#8221;)\nSet objFolderItem = objFolder.ParseName(&#8220;bob.vbs&#8221;)<\/p>\n<p>Set colVerbs = objFolderItem.Verbs\nFor Each objVerb in colVerbs\n    Wscript.Echo objVerb\nNext\n<\/PRE>\n<P>And, yes, these verbs are pretty cool, although they aren\u2019t <I>as<\/I> cool as you might expect. That\u2019s 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 <B>Delete<\/B>, 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\u2019ll see what we mean:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(&#8220;C:\\Windows\\System32&#8221;)\nSet objFolderItem = objFolder.ParseName(&#8220;calc.exe&#8221;)<\/p>\n<p>objFolderItem.InvokeVerb(&#8220;&amp;Delete&#8221;)\n<\/PRE>\n<P>Still, something worth playing around with. <\/P>\n<P>And before you ask, the answer is yes: you can also unpin an item from the Start Menu by using a script:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(&#8220;C:\\Windows\\System32&#8221;)\nSet objFolderItem = objFolder.ParseName(&#8220;calc.exe&#8221;)<\/p>\n<p>objFolderItem.InvokeVerb(&#8220;Unp&amp;in from Start Menu&#8221;)\n<\/PRE>\n<P>Could life get any better?<\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/nov04\/hey1111.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/nov04\/hey1111.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Can I pin a file to the Start Menu by using a script?&#8212; ZD Hey, ZD. For those of you who haven\u2019t bought Windows XP yet (hey, what\u2019s the matter with you; we Scripting Guys have families to feed!), by default XP\u2019s Start Menu changes over time: the more you use an [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,3,5,226],"class_list":["post-71023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-scripting-guy","tag-vbscript","tag-windows-explorer"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Can I pin a file to the Start Menu by using a script?&#8212; ZD Hey, ZD. For those of you who haven\u2019t bought Windows XP yet (hey, what\u2019s the matter with you; we Scripting Guys have families to feed!), by default XP\u2019s Start Menu changes over time: the more you use an [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71023"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71023\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}