{"id":71653,"date":"2004-08-13T07:42:00","date_gmt":"2004-08-13T07:42:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/13\/can-i-copy-script-output-to-the-clipboard\/"},"modified":"2004-08-13T07:42:00","modified_gmt":"2004-08-13T07:42:00","slug":"can-i-copy-script-output-to-the-clipboard","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/can-i-copy-script-output-to-the-clipboard\/","title":{"rendered":"Can I Copy Script Output to the Clipboard?"},"content":{"rendered":"<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" class=\"nearGraphic\" \/><\/p>\n<p>Hey, Scripting Guy! Is there any way to have my script output copied to the Clipboard? <\/p>\n<p>&#8212; ZW, Marseilles, France<\/p>\n<p><img decoding=\"async\" height=\"5\" width=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"Spacer\" border=\"0\" \/><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" class=\"nearGraphic\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" height=\"288\" width=\"120\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" align=\"right\" alt=\"Script Center\" border=\"0\" title=\"Script Center\" class=\"farGraphic\" \/><\/a><\/p>\n<p>Hey, ZW. Well, as long as you don&rsquo;t mind crazy work-arounds then, yes, it&rsquo;s actually pretty easy to copy script output to the Clipboard. To start with, you need to construct a string that contains the desired output. After that, you create an instance of Internet Explorer, and open it to a blank page. You can then take advantage of the capabilities built into the Internet Explorer object model to copy the string to the Clipboard; in particular, you use the clipboardData.SetData method to accomplish this trick. A simple script to copy something to the Clipboard looks like this:<\/p>\n<pre class=\"codeSample\">strCopy = \"This text has been copied to the clipboard.\"\nSet objIE = CreateObject(\"InternetExplorer.Application\")\nobjIE.Navigate(\"about:blank\")\nobjIE.document.parentwindow.clipboardData.SetData \"text\", strCopy\nobjIE.Quit\n<\/pre>\n<p>Run the script, then open up Notepad and click Paste; you should see your string in all its glory.<\/p>\n<p>By the way, all of this happens &ldquo;under the covers;&rdquo; Internet Explorer won&rsquo;t actually pop up on your screen. That&rsquo;s because, by default, any instance of IE you create from a script runs hidden, at least until you do something like this:<\/p>\n<pre class=\"codeSample\">objIE.Visible = True\n<\/pre>\n<p>For more information about clipboardData.SetData, see the <a target=\"_blank\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms533050(VS.85).aspx\">DHTML reference documentation<\/a> on MSDN.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is there any way to have my script output copied to the Clipboard? &#8212; ZW, Marseilles, France Hey, ZW. Well, as long as you don&rsquo;t mind crazy work-arounds then, yes, it&rsquo;s actually pretty easy to copy script output to the Clipboard. To start with, you need to construct a string that contains [&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,17,3,5],"class_list":["post-71653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-internet-explorer","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is there any way to have my script output copied to the Clipboard? &#8212; ZW, Marseilles, France Hey, ZW. Well, as long as you don&rsquo;t mind crazy work-arounds then, yes, it&rsquo;s actually pretty easy to copy script output to the Clipboard. To start with, you need to construct a string that contains [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71653","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=71653"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71653\/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=71653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}