{"id":4220,"date":"2013-02-03T00:01:00","date_gmt":"2013-02-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/02\/03\/weekend-scripter-create-a-sendto-notepad-shortcut\/"},"modified":"2013-02-03T00:01:00","modified_gmt":"2013-02-03T00:01:00","slug":"weekend-scripter-create-a-sendto-notepad-shortcut","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-create-a-sendto-notepad-shortcut\/","title":{"rendered":"Weekend Scripter: Create a SendTo Notepad Shortcut"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary:<\/strong><span style=\"font-size: 12px\"> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to create a SendTo Notepad shortcut.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. I absolutely love using Windows&nbsp;8. To me, it is the best operating system we have ever released at Microsoft. I am especially proud that some of the Help articles I wrote are actually included with Windows PowerShell Help&mdash;it is so cool!<\/p>\n<p>Anyway, one of my favorite things to do is to have a shortcut to Notepad in the <strong>SendTo<\/strong> special folder. This way, I can open and look at a lot of things without having to change file associations. I simply right-click, and select <strong>Notepad<\/strong> from the <strong>SendTo<\/strong> menu. In Windows&nbsp;8, this is not a default location.<\/p>\n<p>In the following image, I right-click the&nbsp;<strong>CreatePoshOrgPro<\/strong>&hellip; script, and point to <strong>Send to<\/strong>, but Notepad.exe is not listed as a default location to send items.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4336.wes-2-3-13-01.png\"><img decoding=\"async\" title=\"Image of file directory\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4336.wes-2-3-13-01.png\" alt=\"Image of file directory\" \/><\/a><\/p>\n<h2>Finding the SendTo folder<\/h2>\n<p>Ok, so I know that <strong>SendTo<\/strong> is a special folder. I guess I can open my user profile folder, find the <strong>SendTo<\/strong> folder and create a shortcut to Notepad there&mdash;I have done this literally dozens of times over the past few years. But when I attempt to do this, I get access denied. On closer inspection, the <strong>SendTo<\/strong> folder is not a real folder, but it redirects to another location.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8407.wes-2-3-13-02.png\"><img decoding=\"async\" title=\"Image of Windows Explorer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8407.wes-2-3-13-02.png\" alt=\"Image of Windows Explorer\" \/><\/a><\/p>\n<p>Hmm &hellip; So I squirrel around trying to find where we hid the <strong>SendTo<\/strong> folder, and then I was reading over the text of my new <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-3-0-Step\/dp\/0735663394\/ref=sr_1_1?ie=UTF8&amp;qid=1344869046&amp;sr=8-1&amp;keywords=powershell%203.0\" target=\"_blank\">Windows PowerShell 3.0 Step by Step<\/a> book by Microsoft Press, and I ran across the section where I talked about using the old-fashioned <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aew9yb99(v=VS.84).aspx\" target=\"_blank\">WshShell object<\/a>. It dawned on me that I could use this object to completely solve my problem. To begin with, the <strong>WshShell<\/strong> object is a <strong>COM<\/strong> object, so I need to create an instance of the object by using <strong>New-Object<\/strong>. I store the returned <strong>COM<\/strong> object in the <strong>$wshshell<\/strong> variable, as shown here.<\/p>\n<p style=\"padding-left: 30px\">$wshshell = New-Object -com wscript.shell<\/p>\n<p>When I call the <strong>SpecialFolders<\/strong> property, I receive a listing of all the special folders about which the object knows. Here is the syntax I use.<\/p>\n<p style=\"padding-left: 30px\">$wshshell.SpecialFolders<\/p>\n<p>The command and the output from the command are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0675.wes-2-3-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0675.wes-2-3-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>It is common that many <strong>COM<\/strong> objects have an <strong>item<\/strong><em> <\/em>method. I decide to see if the <strong>SpecialFolders<\/strong> collection has one &hellip; if it does, I will feed it the specific <strong>SendTo<\/strong><em> <\/em>folder. As shown here, the command works great.<\/p>\n<p style=\"padding-left: 30px\">11:08 C:\\&gt; $wshshell.SpecialFolders.Item(&#8220;sendto&#8221;)<\/p>\n<p style=\"padding-left: 30px\">C:\\Users\\ed.IAMMRED\\AppData\\Roaming\\Microsoft\\Windows\\SendTo<\/p>\n<h2>So I have the path to the SendTo folder &hellip;<\/h2>\n<p>I paste the path from the $wshshell.SpecialFolders.Item(&#8220;sendto&#8221;) command to the Windows Explorer path bar, and sure enough the <strong>SendTo<\/strong> folder opens. While I am there, I decide to delete a few things I never use.<\/p>\n<p>I could go ahead and create a new shortcut here, but, dude, that would be like using the GUI and would be the first step to becoming a button monkey &hellip; somehow I cannot see myself doing that.<\/p>\n<p>The <strong>SendTo<\/strong> folder is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4848.wes-2-3-13-04.png\"><img decoding=\"async\" title=\"Image of SendTo folder\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4848.wes-2-3-13-04.png\" alt=\"Image of SendTo folder\" \/><\/a><\/p>\n<h2>Hey, I bet I can script it &hellip;<\/h2>\n<p>Well, it did not take much time to knock off a quick script. The first thing I need to do is to create the <strong>WshShell<\/strong> object and get the path to the <strong>SendTo<\/strong> folder&mdash;I had already written that code.<\/p>\n<p style=\"padding-left: 30px\">$wshshell = New-Object -com wscript.shell<\/p>\n<p style=\"padding-left: 30px\">$path = $wshshell.SpecialFolders.Item(&#8220;sendto&#8221;)<\/p>\n<p>Next, I need to create a path to use for the shortcut. I like to use <strong>Join-Path<\/strong> to create paths because it reduces possible concatenation errors.<\/p>\n<p style=\"padding-left: 30px\">$shortcutPath = Join-Path -Path $path -ChildPath &#8220;Notepad.lnk&#8221;<\/p>\n<p>Now, I need to call the <strong>CreateShort<\/strong> method and pass the path for the shortcut. I have to store the returned object, because I need to specify a couple of properties. I put the object in the <strong>$shortcut<\/strong> variable.<\/p>\n<p style=\"padding-left: 30px\">$shortcut = $wshshell.CreateShortcut($shortcutPath)<\/p>\n<p>Now, I need to specify the target&mdash;because Notepad is a well-known application I can avoid specifying the full path to the file. The description is not a requirement, but I like to fill out descriptions when they are available.<\/p>\n<p style=\"padding-left: 30px\">$shortcut.TargetPath = &#8220;Notepad.exe&#8221;<\/p>\n<p style=\"padding-left: 30px\">$shortcut.Description = &#8220;Created by Powershell 3.0&#8221;<\/p>\n<p> Finally, I need to save my work and create the shortcut.<\/p>\n<p style=\"padding-left: 30px\">$shortcut.Save()<\/p>\n<p>I mouse over to the <strong>SendTo<\/strong> folder, and cool it worked!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2553.wes-2-3-13-05.png\"><img decoding=\"async\" title=\"Image of Properties folder\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2553.wes-2-3-13-05.png\" alt=\"Image of Properties folder\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\">CreateNotePadShortCutInSendTo.ps1<\/p>\n<p style=\"padding-left: 30px\">$wshshell = New-Object -com wscript.shell<\/p>\n<p style=\"padding-left: 30px\">$path = $wshshell.SpecialFolders.Item(&#8220;sendto&#8221;)<\/p>\n<p style=\"padding-left: 30px\">$shortcutPath = Join-Path -Path $path -ChildPath &#8220;Notepad.lnk&#8221;<\/p>\n<p style=\"padding-left: 30px\">$shortcut = $wshshell.CreateShortcut($shortcutPath)<\/p>\n<p style=\"padding-left: 30px\">$shortcut.TargetPath = &#8220;Notepad.exe&#8221;<\/p>\n<p style=\"padding-left: 30px\">$shortcut.Description = &#8220;Created by Powershell 3.0&#8221;<\/p>\n<p style=\"padding-left: 30px\">$shortcut.Save()<\/p>\n<p>I uploaded the <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Create-Shortcut-to-Notepad-63fd4d25\" target=\"_blank\">complete CreateNotePadShortCutInSendTo.ps1 script<\/a> to the Scripting Guys Script Repository to make it easy for you to use the code.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to create a SendTo Notepad shortcut. Microsoft Scripting Guy, Ed Wilson, is here. I absolutely love using Windows&nbsp;8. To me, it is the best operating system we have ever released at Microsoft. I am especially proud that some of the Help articles I wrote [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,3,94,61,45],"class_list":["post-4220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-scripting-guy","tag-special-folders","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to create a SendTo Notepad shortcut. Microsoft Scripting Guy, Ed Wilson, is here. I absolutely love using Windows&nbsp;8. To me, it is the best operating system we have ever released at Microsoft. I am especially proud that some of the Help articles I wrote [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4220","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4220"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4220\/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=4220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}