{"id":69853,"date":"2005-05-09T15:50:00","date_gmt":"2005-05-09T15:50:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/05\/09\/how-can-i-create-a-shortcut-in-my-network-places\/"},"modified":"2005-05-09T15:50:00","modified_gmt":"2005-05-09T15:50:00","slug":"how-can-i-create-a-shortcut-in-my-network-places","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-create-a-shortcut-in-my-network-places\/","title":{"rendered":"How Can I Create a Shortcut in My Network Places?"},"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 shortcut in My Network Places?<BR><BR>&#8212; KP<\/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, KP. You\u2019ll have to excuse us if we sound a little out of breath; we\u2019ve been running around like crazy looking for a complicated and highly-technical solution to this problem. It was only after we failed miserably in that quest that we began to think about what we were trying to do. Maybe we were trying to make this much harder than we needed to. After all, My Network Places is nothing more than a folder on the hard disk, and a \u201cnetwork place\u201d is nothing more than a shortcut. Could creating a network place involve nothing more than creating a shortcut in a folder? You be the judge:<\/P><PRE class=\"codeSample\">Const NETHOOD = &amp;H13&amp;<\/p>\n<p>Set objWSHShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nSet objShell = CreateObject(&#8220;Shell.Application&#8221;)<\/p>\n<p>Set objFolder = objShell.Namespace(NETHOOD)\nSet objFolderItem = objFolder.Self\nstrNetHood = objFolderItem.Path<\/p>\n<p>strShortcutName = &#8220;Finance Department Public Folder&#8221;\nstrShortcutPath = &#8220;\\\\atl-finance-01\\public&#8221;<\/p>\n<p>Set objShortcut = objWSHShell.CreateShortcut _\n    (strNetHood &amp; &#8220;\\&#8221; &amp; strShortcutName &amp; &#8220;.lnk&#8221;)\nobjShortcut.TargetPath = strShortcutPath\nobjShortcut.Save\n<\/PRE>\n<P>We begin by defining a constant named NETHOOD and assigning it the value &amp;H13&amp;; we\u2019ll use this in a moment to locate the My Network Places folder. We then create instances of two difference objects: the Windows Script Host <B>Shell<\/B> object and the Windows <B>Shell<\/B> object. That\u2019s what these two lines of code do:<\/P><PRE class=\"codeSample\">Set objWSHShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nSet objShell = CreateObject(&#8220;Shell.Application&#8221;)\n<\/PRE>\n<P>Next we use a Windows Shell object method and property &#8211; <B>Namespace<\/B> and <B>Self<\/B>, respectively &#8211; to determine the location of the My Network Places folder. The Namespace method actually locates the folder for us; however, it returns a <B>Folder<\/B> object. For technical reasons we don\u2019t need to worry about, we can\u2019t do much with this object; therefore we use the Self property to return a <B>FolderItem<\/B> object representing the My Network Places folder. We do that because a FolderItem object is something that our script <I>can<\/I> deal with.<\/P>\n<P>As soon as we have a FolderItem we can then grab the <B>Path<\/B> property and assign it to the variable strNetHood; strNetHood will now be equal to something along the lines of C:\\Documents and Settings\\kenmyer\\NetHood. And, yes, that <I>is<\/I> a long and convoluted explanation for just three lines of code:<\/P><PRE class=\"codeSample\">Set objFolder = objShell.Namespace(NETHOOD)\nSet objFolderItem = objFolder.Self\nstrNetHood = objFolderItem.Path\n<\/PRE>\n<P>Next we simply assign the name of the shortcut and the path to our network place to a pair of variables. We don\u2019t really need to do this; we could just hard-code the values into the script. But assigning the values to variables will make it a little easier for you to modify the script to fit your own needs.<\/P>\n<P>Now we turn to the WSH Shell object to actually create our shortcut. We begin by calling the <B>CreateShortcut<\/B> method, passing it the path to the new shortcut name. That will be a combination of four items: the path to the My Network Places folder (strNetHood), a trailing \\, the name of our new shortcut (strShortcutName), and the file extension <B>.lnk<\/B>. That gives us a shortcut path similar to this:<\/P><PRE class=\"codeSample\">C:\\Documents and Settings\\kenmyer\\NetHood\\Finance Department Public Folder.lnk\n<\/PRE>\n<P>We set the <B>TargetPath<\/B> property of the shortcut to the network place (\\\\atl-finance-01\\public) and then call the <B>Save<\/B> method to write the new shortcut to the file system. Just like that, we have a new network place.<\/P>\n<P>Now, if you\u2019ll excuse us, we need to go lie down for a moment. Who\u2019d have thought that scripting would be such hard work?<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I create a shortcut in My Network Places?&#8212; KP Hey, KP. You\u2019ll have to excuse us if we sound a little out of breath; we\u2019ve been running around like crazy looking for a complicated and highly-technical solution to this problem. It was only after we failed miserably in that quest [&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":[237,16,3,5],"class_list":["post-69853","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-basic-computer-information","tag-desktop-management","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I create a shortcut in My Network Places?&#8212; KP Hey, KP. You\u2019ll have to excuse us if we sound a little out of breath; we\u2019ve been running around like crazy looking for a complicated and highly-technical solution to this problem. It was only after we failed miserably in that quest [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69853","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=69853"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69853\/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=69853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}