<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Software Sleuthing : Command Line</title><link>http://blogs.msdn.com/joshpoley/archive/tags/Command+Line/default.aspx</link><description>Tags: Command Line</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Running JScript in a CMD File</title><link>http://blogs.msdn.com/joshpoley/archive/2008/01/15/running-jscript-in-a-cmd-file.aspx</link><pubDate>Tue, 15 Jan 2008 19:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7118863</guid><dc:creator>joshpoley</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/joshpoley/comments/7118863.aspx</comments><wfw:commentRss>http://blogs.msdn.com/joshpoley/commentrss.aspx?PostID=7118863</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;I do a lot of work from a command shell and this is a little hack that I threw together to avoid having to type out "cscript" every time I wanted to run some specific JScript (aka JavaScript) file. Using some arcane aspects of the two languages, it is possible to embed the JScript code in a .cmd file which the command shell can initially execute and then pass off to cscript.exe for the heavy lifting. Below is a sample file, if it all makes sense you can stop reading now, otherwise continue on to see what is happening.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;test.cmd&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;1&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@set @cmdinterop=1 /*&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;2&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@echo off&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;3&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set @cmdinterop=&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;4&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cscript //E:JSCRIPT "%~dpnx0" %*&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;5&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;goto :eof&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;6&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;7&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;8&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;var today = new Date();&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;9&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;10&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WScript.Echo(today);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The main thing to remember is that the whole file is parsed by &lt;I style="mso-bidi-font-style: normal"&gt;both&lt;/I&gt; cmd.exe and then cscript.exe. With that key piece of information let's step through the file.&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;CMD.EXE&lt;/FONT&gt;&lt;/H2&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;1&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;@set&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt; @cmdinterop=1 /*&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;CMD sees the @ symbols which means "no echo", and then creates a new environment variable named "@cmdinterop" and sets its value to "1 /*". "@cmdinterop" is just a random name we've picked which has no special meaning in and of itself, though the 'at' symbol is important; more information on this will come later.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;2&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;@echo &lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;off&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Turn off future echoing of commands.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;3&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt; @cmdinterop=&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Nuke the environment variable we just set. Someone looking at this might be thinking: not the most efficient CMD script. If we don't need or use the environment variable, why do we create it? The reason is because the first line needs to be a benign statement in both languages: CMD and JScript. It just so happens that "@set" has meaning in both languages and so we make use of that fact to do our dirty work. This line will just clean up what we had to do on line 1, with regard to CMD's processing.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;4&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;cscript //E:JSCRIPT "%~dpnx0" %*&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;We now have the CMD script invoke cscript.exe and pass in the name of the current file. The "%~…0" syntax is the cryptic way to get at the file-system properties for the current executing script: "d" for drive letter, "p" for path, "n" for the filename, and "x" for the file's extension. We also attempt to pass in any additional parameters by using the "%*" syntax.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;At this point, CMD sits and waits for cscript.exe to finish executing, but we will just continue on since we are almost done with CMD's processing:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;5&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;goto&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt; :eof&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;CMD now jumps to the end of the file, thus bypassing all of our JScript code (lines 6+).&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;CSCRIPT.EXE&lt;/FONT&gt;&lt;/H2&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;1&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;@set @&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;cmdinterop=1 &lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;/*&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;In JScript, "@set @" creates a variable which can be used for conditional compilation. We don’t really care about the variable which gets created as we will never use it, but what we do care about is being able inject the start of the block comment, which will allow us to ignore all the CMD code (lines 2 through 5):&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;2&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;@echo off&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;3&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;set @cmdinterop=&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;4&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;cscript //E:JSCRIPT "%~dpnx0" %*&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;5&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;goto :eof&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;6&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Once we skip past all the CMD code we are free to use whatever JScript code we want:&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;7&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;8&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;var &lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;today = &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue; mso-bidi-font-size: 9.0pt"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;Date();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;9&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;10&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WScript.Echo(today);&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;@set&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;From the JScript parser, things are easy as long as you can get the start of a comment block going. The tricky part is getting that "/*" to parse in CMD without causing an error. Luckily for us, "@set" is the magic code which gives us the avenue to do just that because it can be parsed by both languages.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Going forward, you may want to be nice to future readers of your code and sprinkle in a few extra comments:&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR: #aaaaaa"&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#050505&gt;@set @cmdinterop=1 &lt;/FONT&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-size: 9.0pt; mso-themecolor: text1"&gt;/*&lt;/SPAN&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt; this line interpreted by both CMD and JSCRIPT&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#050505&gt;@&lt;/FONT&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;REM Start of the CMD code&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;@echo off&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;set @cmdinterop=&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;cscript //E:JSCRIPT "%~dpnx0" %*&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;goto :eof&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New"&gt;REM end of the CMD code&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New" color=#050505&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: green; mso-bidi-font-size: 9.0pt"&gt;&lt;FONT style="BACKGROUND-COLOR: #aaaaaa" face="Courier New"&gt;// Start of the JScript Code:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: 68.25pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Standard Disclaimer: As mentioned earlier, this is a hack. I've tested and used this on XP SP2, but changes to the languages and parsers may cause this script to break.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7118863" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/joshpoley/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.msdn.com/joshpoley/archive/tags/Command+Line/default.aspx">Command Line</category></item><item><title>WinDbg’s Hidden Tools</title><link>http://blogs.msdn.com/joshpoley/archive/2008/01/02/windbg-s-hidden-tools.aspx</link><pubDate>Wed, 02 Jan 2008 22:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6958044</guid><dc:creator>joshpoley</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/joshpoley/comments/6958044.aspx</comments><wfw:commentRss>http://blogs.msdn.com/joshpoley/commentrss.aspx?PostID=6958044</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;If you install WinDbg (&lt;A href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx"&gt;http://www.microsoft.com/whdc/devtools/debugging/default.mspx&lt;/A&gt;), you also get a handful of additional command line tools which aren’t necessarily very visible. Some of them are just console versions of the kernel debugger (such as i386kd.exe) and others are for helping you manage a symbol server, but there are a few useful utilities in there that are worth some advertisement to the uninitiated.&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;tlist.exe&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This tool will display all the processes which are currently running and can also give you some useful information about them. For example, the “-c” switch will display the arguments passed into an application and will also often show the full path to the location of the executable. And if you ever need to know exactly &lt;I style="mso-bidi-font-style: normal"&gt;which&lt;/I&gt; DLLs a program is actually using (as your system will often have multiple copies floating around), tlist can tell you that as well.&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;kill.exe&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;One of the other frequently used tools is kill.exe. No more Mr. Nice Guy, this little app will abruptly terminate any application. For the times that a hung program just won’t go away, no matter how much prodding you give it from the UI, “kill.exe -f” is often the quickest solution.&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;agestore.exe&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This little utility lets you easily delete files based off of the last time a file was &lt;I style="mso-bidi-font-style: normal"&gt;accessed&lt;/I&gt;. This is great for cleaning out old test reports, build logs, or even symbol files (which is why this tool comes with WinDbg).&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=3&gt;dumpchk.exe&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This application will take a crash dump file and spew out a plethora of information about the crash. This is handy when you want to see some information about a crash dump without having to go all the way into a debugger. This is also a great tool for creating standardized crash logs which you can attach to bug reports.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6958044" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/joshpoley/archive/tags/Command+Line/default.aspx">Command Line</category></item></channel></rss>