{"id":71563,"date":"2004-08-26T15:44:00","date_gmt":"2004-08-26T15:44:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/26\/can-i-change-the-command-window-title-when-running-a-script\/"},"modified":"2004-08-26T15:44:00","modified_gmt":"2004-08-26T15:44:00","slug":"can-i-change-the-command-window-title-when-running-a-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/can-i-change-the-command-window-title-when-running-a-script\/","title":{"rendered":"Can I Change the Command Window Title When Running a Script?"},"content":{"rendered":"<p><img decoding=\"async\" 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\"><\/p>\n<p>Hey, Scripting Guy! When I run a batch file, I can use the Title command to change the caption of the command window. Can I change the caption of the command window from within a script?<\/p>\n<p>&#8212; AA, Yokohama, Japan<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><img decoding=\"async\" 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 decoding=\"async\" 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><\/p>\n<p>Hey, AA. Well, yes, as long as you\u2019re willing to open up a new command window. If you are, then you can use code similar to this:<\/p>\n<pre class=\"codeSample\">Set objShell = CreateObject(\"Wscript.Shell\")\nobjShell.Run _\n    (\"%comspec% \/K title My Command Window |ping.exe 192.168.1.1\"), _\n        1, TRUE\n<\/pre>\n<p>Notice what we\u2019ve done here. We\u2019ve created an instance of the Wscript.Shell object, and then we\u2019ve used the Run method to run Ping.exe. But see the big, long command string we used to run the script? What we\u2019ve done is call %comspec% to open a new command window. We used the \/K switch to ensure that the window remains open after the script finishes, and we\u2019ve set the title of the window to My Command Window. That\u2019s fairly straightforward.<\/p>\n<p>The tricky part comes when we run Ping; we have to use the pipe separator (the | character) to essentially open a command window and run Ping all in one motion. What we\u2019re saying here is, \u201cOpen a command window, set the window title, and run Ping.exe, all at the same time.\u201d Without the piping, the script would open a command window titled My Command Window, but then open a <i>second<\/i> command window (with the default title) and run Ping in that second window. If you want to see what we\u2019re talking about, try this:<\/p>\n<pre class=\"codeSample\">Set objShell = CreateObject(\"Wscript.Shell\")\nobjShell.Run(\"%comspec% \/K title My Command Window \"), 1, TRUE\nobjShell.Run(\"ping.exe 192.168.1.1\"), 1, TRUE\n<\/pre>\n<p>By the way, if you want to get <i>really<\/i> fancy (or at least as fancy as the command shell allows you to get), you can change the foreground and background colors of the window at the same time you change the title. Dying to have light yellow text on a green background? Then run this script:<\/p>\n<pre class=\"codeSample\">Set objShell = CreateObject(\"Wscript.Shell\")\nobjShell.Run _\n    (\"%comspec% \/T:2E \/K title My Command Window|ping.exe \" &amp; _\n        \"192.168.1.1\"), 1, TRUE\n<\/pre>\n<p>The secret here is the mysterious little switch \/T:2E, which enables you to change the foreground and background colors. For more information, open up a command window and type this:<\/p>\n<pre class=\"codeSample\">color \/?\n<\/pre>\n<p><br><\/p>\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\/aug04\/hey0826.mspx#top\"><img decoding=\"async\" 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\/aug04\/hey0826.mspx#top\">Top of page<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! When I run a batch file, I can use the Title command to change the caption of the command window. Can I change the caption of the command window from within a script? &#8212; AA, Yokohama, Japan Hey, AA. Well, yes, as long as you\u2019re willing to open up a new command [&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":[2,3,4,5],"class_list":["post-71563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-running","tag-scripting-guy","tag-scripting-techniques","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! When I run a batch file, I can use the Title command to change the caption of the command window. Can I change the caption of the command window from within a script? &#8212; AA, Yokohama, Japan Hey, AA. Well, yes, as long as you\u2019re willing to open up a new command [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71563","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=71563"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71563\/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=71563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}