{"id":70323,"date":"2005-03-02T22:19:00","date_gmt":"2005-03-02T22:19:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/03\/02\/how-can-i-create-a-folder-on-the-start-menu\/"},"modified":"2005-03-02T22:19:00","modified_gmt":"2005-03-02T22:19:00","slug":"how-can-i-create-a-folder-on-the-start-menu","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-create-a-folder-on-the-start-menu\/","title":{"rendered":"How Can I Create a Folder on the Start Menu?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I create a folder on the Start menu? I want the folder to be named the same as the <I>%username%<\/I> environment variable.<BR><BR>&#8212; SB<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, SB. As we are wont to do, we\u2019re going to break this question down into subtasks. We\u2019ll explain how to do each of these subtasks, then at the end put the pieces together to create a single script that solves your problem for you.<\/P>\n<P>To begin with, we need to figure out the name of the logged-on user (which happens to map to the <I>%username% <\/I>environment variable). That\u2019s easy: we just create an instance of the WSH <B>Network<\/B> object and retrieve the value of the <B>UserName<\/B> property. That\u2019s what we do here:<\/P><PRE class=\"codeSample\">Set objNetwork = CreateObject(&#8220;Wscript.Network&#8221;)\nstrUser = objNetwork.UserName\nstrPath = &#8220;C:\\Documents and Settings\\&#8221; &amp; strUser\n<\/PRE>\n<P>Note that we\u2019ve also created a variable named strPath and assigned it the value <B>C:\\Documents and Settings\\<\/B> plus the user name (e.g., <B>kenmyer<\/B>). That gives us a path to a user folder like <B>C:\\Documents and Settings\\kenmyer<\/B>. If you want to create a shortcut to a different folder (for example, <B>\\\\atl-fs-01\\public\\kenmyer)<\/B>, you just need to change this line of code accordingly.<\/P>\n<P>Next we need to determine the locations of the Start menu Programs folder. That\u2019s also easy. This time we create an instance of the WSH <B>Shell<\/B> object and call the <B>SpecialFolders<\/B> method, telling SpecialFolders we\u2019d like the location of the Programs folder. We store the folder path in the variable strPrograms:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nstrPrograms = objShell.SpecialFolders(&#8220;Programs&#8221;)\n<\/PRE>\n<P>(By the way, if you\u2019d like to know the other folder paths you can locate using the SpecialFolders method, take a look at the <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_wsh_xkki.mspx\"><B>\u201cWorking With Special Folders\u201d<\/B><\/A> section of the Microsoft Windows 2000 Scripting Guide.)<\/P>\n<P>Finally we need to create the Start menu shortcut. Here\u2019s the code that does that:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nSet objShellLink = objShell.CreateShortcut(strPrograms &amp; &#8220;\\&#8221; &amp; strUser &amp; &#8220;.lnk&#8221;)\nobjShellLink.TargetPath = strPath\nobjShellLink.Description = &#8220;Home folder for &#8221; &amp; strUser\nobjShellLink.WorkingDirectory = strPath\nobjShellLink.Save\n<\/PRE>\n<P>Here we again use the WSH <B>Shell<\/B> object, this time calling the <B>CreateShortcut<\/B> method. To create the Start menu shortcut we need to pass CreateShortcut the complete path to the shortcut file we want to create (for example, C:\\Documents and Settings\\kenmyer\\kenmyer.lnk). To determine this path, we simply combine the path to the user folder (<B>C:\\Documents and Settings\\kenmyer<\/B>), a slash (<B>\\<\/B>), the user name (<B>kenmyer<\/B>), and the file extension for a shortcut file (<B>.lnk<\/B>). That\u2019s what we do with this line of code:<\/P>\n<P>Set objShellLink = objShell.CreateShortcut(strPrograms &amp; &#8220;\\&#8221; &amp; strUser &amp; &#8220;.lnk&#8221;)<\/P>\n<P>Next we assign values to some of the shortcut file\u2019s properties. The <B>TargetPath<\/B> represents the path to the folder; thus we assign it the path to the folder. The <B>Description<\/B> represents the tooltip that appears when you pause the mouse over the item in the Start menu; it gets a simple description indicating that it\u2019s the home folder for the logged-on user. Finally, <B>WorkingDirectory<\/B> represents, well, the working directory for the shortcut; it gets assigned the path to the folder. After assigning these property values we call the <B>Save<\/B> method to save the shortcut file and add it to the Start menu.<\/P>\n<P>Now, as promised, here\u2019s a script that combines all three of our subtasks:<\/P><PRE class=\"codeSample\">Set objNetwork = CreateObject(&#8220;Wscript.Network&#8221;)\nstrUser = objNetwork.UserName\nstrPath = &#8220;C:\\Documents and Settings\\&#8221; &amp; strUser<\/p>\n<p>Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nstrPrograms = objShell.SpecialFolders(&#8220;Programs&#8221;)<\/p>\n<p>Set objShellLink = objShell.CreateShortcut(strPrograms &amp; &#8220;\\&#8221; &amp; strUser &amp; &#8220;.lnk&#8221;)\nobjShellLink.TargetPath = strPath\nobjShellLink.Description = &#8220;Home folder for &#8221; &amp; strUser\nobjShellLink.WorkingDirectory = strPath\nobjShellLink.Save\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I create a folder on the Start menu? I want the folder to be named the same as the %username% environment variable.&#8212; SB Hey, SB. As we are wont to do, we\u2019re going to break this question down into subtasks. We\u2019ll explain how to do each of these subtasks, then [&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":[11,3,12,5],"class_list":["post-70323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-folders","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I create a folder on the Start menu? I want the folder to be named the same as the %username% environment variable.&#8212; SB Hey, SB. As we are wont to do, we\u2019re going to break this question down into subtasks. We\u2019ll explain how to do each of these subtasks, then [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70323","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=70323"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70323\/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=70323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}