<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Mark Yocom's Script Tips</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/myocom/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/myocom/feed.xml</link>
    <description>Scripting tips, covering batch, VBScript, and the occasional Perl script.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:25:13 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Windows command line references</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/windows-command-line-references</link>
      <pubDate>Mon, 28 Jan 2008 17:32:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2008/01/28/windows-command-line-references/</guid>
      <description><![CDATA[I found that TechNet has references for the Windows command line utilities.&nbsp; Much of these are...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2>I found that TechNet has references for the Windows command line utilities.&nbsp; Much of these are just a rehash of the help you'd get with /? but at least they're easier to read...</P>
<P><A class="" href="https://technet2.microsoft.com/windowsserver/en/library/552ed70a-208d-48c4-8da8-2e27b530eac71033.mspx?mfr=true" target=_blank mce_href="https://technet2.microsoft.com/windowsserver/en/library/552ed70a-208d-48c4-8da8-2e27b530eac71033.mspx?mfr=true">This</A> is a list of commands for Windows Server 2003 (most apply to Windows XP as well), and&nbsp;<A class="" href="https://technet2.microsoft.com/windowsserver2008/en/library/69baa34b-d4b3-40ec-bd2f-12d98f7802d51033.mspx?mfr=true" target=_blank mce_href="https://technet2.microsoft.com/windowsserver2008/en/library/69baa34b-d4b3-40ec-bd2f-12d98f7802d51033.mspx?mfr=true">here</A> is the list for Vista and Server 2008.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>On blogging tools</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/on-blogging-tools</link>
      <pubDate>Sat, 26 Aug 2006 00:02:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2006/08/26/on-blogging-tools/</guid>
      <description><![CDATA[One of the obstacles to frequent posting (at least mine) is that the types of posts I typically make...]]></description>
      <content:encoded><![CDATA[<P>One of the obstacles to frequent posting (at least mine) is that the types of posts I typically make include code.&nbsp; Code that I would like to be formatted nicely.&nbsp; Unfortunately, this previously meant hand-crafting HTML to make it all look nice.&nbsp; In some cases, I could write up scripts in Visual Studio and paste them into an editor which would (mostly) preserve the formatting, but having to write batch files in VS seems hugely overkill.&nbsp; Anyway, since that was such a pain, I didn't post often.</P>
<P>Enter <A href="https://windowslivewriter.spaces.live.com/" target=_blank mce_href="https://windowslivewriter.spaces.live.com/">Windows Live Writer</A>.&nbsp; Everyone else is blogging about it, so hey, why shouldn't I?&nbsp; Out of the box, it's very, very nice (and free, to boot!).&nbsp; It's a truly WYSIWYG editor (not the typical WYSI-more or less-WYG-with a few little problems here and there) and that handles all of my typical blogging needs.&nbsp; <EM>Except</EM> the whole code formatting thing.&nbsp; Aha, you say, how does that help?&nbsp; </P>
<P>Easy.&nbsp; </P>
<P>WLW supports plugins, and they're (evidently) easy to develop.&nbsp; Even though it's still in beta, there are dozens of plugins already.&nbsp; A few of those plugins enable code formatting.&nbsp; I've chosen to use Steve Dunn's cleverly named <A href="https://stevedunns.blogspot.com/2006/08/code-formatter-plugin-for-windows-live.html" target=_blank mce_href="https://stevedunns.blogspot.com/2006/08/code-formatter-plugin-for-windows-live.html">Code Formatter Plugin</A>, which uses Actipro's <A href="https://www.actiprosoftware.com/Products/DotNet/CodeHighlighter/Default.aspx" target=_blank mce_href="https://www.actiprosoftware.com/Products/DotNet/CodeHighlighter/Default.aspx">CodeHighlighter</A> web control.&nbsp; Most of the code highlighters out there only seem to support the Visual Studio types of code (your C, your VB.Net, etc.).&nbsp; Try to get scripts highlighted and forget about it.&nbsp; This one does, though, and even though it's not <EM>quite</EM> the same style of highlighting I'm used to, it's way better than nothing.</P>
<P>Take the scriptlet I wrote in&nbsp;<A href="https://blogs.msdn.com/myocom/archive/2005/06/03/425046.aspx" target=_blank mce_href="https://blogs.msdn.com/myocom/archive/2005/06/03/425046.aspx">this post</A>.&nbsp; Hand-styling that was a huge pain, and all I really did was keep the indenting and ensure it was all in a fixed-width font.&nbsp; But all that indenting added up to a lot of &amp;nbsp;'s and it was easy to lose track of how many I'd already done.</P>
<P>With this plugin to WLW, though, it's a matter of clicking "Insert Formatted Code" or "Insert Clipboard as Code" and you get this instead:</P>
<P mce_keep="true">&nbsp;</P>
<DIV class=wlWriterSmartContent id=57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:28c2175f-f606-4528-9f8f-3675826f243e contentEditable=false style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"><PRE style="BACKGROUND-COLOR: white"><DIV><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><SPAN style="COLOR: #008080">1</SPAN> <SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">f </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">delims=/ tokens=1-3</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> %%a in </SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%DATE:~4%</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">do</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">
</SPAN><SPAN style="COLOR: #008080">2</SPAN> <SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">f </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">delims=:. tokens=1-4</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> %%m in </SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">%TIME%</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">do</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">
</SPAN><SPAN style="COLOR: #008080">3</SPAN> <SPAN style="COLOR: #000000">        </SPAN><SPAN style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000"> FILENAME</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">basename-%%c-%%b-%%a-%%m%%n%%o%%p
</SPAN><SPAN style="COLOR: #008080">4</SPAN> <SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">
</SPAN><SPAN style="COLOR: #008080">5</SPAN> <SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000">)</SPAN></DIV></PRE></DIV>
<P mce_keep="true">Line numbers and everything.&nbsp; In the future, I'll skip the line numbers for bits of script I intend for people to copy and paste, but to illustrate points, I'll include them.</P>
<P>Ok, enough rah-rah from me.&nbsp; I have scripts to write.</P>
<P><FONT size=1>(But seriously.&nbsp; If you blog, this is an awesome tool.)</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Definitive list of illegal filenames?</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/definitive-list-of-illegal-filenames</link>
      <pubDate>Tue, 11 Jul 2006 15:11:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2006/07/11/definitive-list-of-illegal-filenames/</guid>
      <description><![CDATA[Earlier, I tried to come up with a definitive list of illegal filesystem names, but it seems this is...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2><A href="https://blogs.msdn.com/myocom/archive/2005/06/08/427043.aspx">Earlier</A>, I tried to come up with a definitive list of illegal filesystem names, but it seems this is already documented.&nbsp; Who knew?</FONT></P>
<P><A href="https://support.microsoft.com/Default.aspx?id=74496"><FONT face=Verdana size=2>https://support.microsoft.com/Default.aspx?id=74496</FONT></A></P>]]></content:encoded>
    </item>
    <item>
      <title>More on command line redirection</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/more-on-command-line-redirection</link>
      <pubDate>Wed, 17 May 2006 13:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2006/05/17/more-on-command-line-redirection/</guid>
      <description><![CDATA[For those of you who are more interested in the gritty details of command line redirection, RaymondC...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2>For those of you who are more interested in the gritty details of <A href="https://blogs.msdn.com/myocom/archive/2005/06/08/427043.aspx">command line redirection</A>, RaymondC has posted a couple of great articles recently on his excellent <A HREF="/oldnewthing">The Old New Thing</A>&nbsp;blog.&nbsp; </FONT></P>
<P><FONT face=Verdana size=2>The <A HREF="/oldnewthing/archive/2006/05/16/598893.aspx">first</A>&nbsp;discusses how (and more importantly, <EM>why</EM>) the redirection symbols are parsed by CMD.EXE rather than the program you're calling.&nbsp; </FONT></P>
<P><FONT face=Verdana size=2>The <A HREF="/oldnewthing/archive/2006/05/17/599916.aspx">second</A> points out some of the caveats of blindly accepting input from environment variables.&nbsp; While it may be a pain to quote the parameters your script takes, it can make troubleshooting easier and, as his post points out, can prevent your day from being ruined.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Evolution of a solution</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/evolution-of-a-solution</link>
      <pubDate>Sat, 01 Oct 2005 01:15:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/10/01/evolution-of-a-solution/</guid>
      <description><![CDATA[The other day, someone posted a message at work asking for a way to find out the drive letter for...]]></description>
      <content:encoded><![CDATA[<font face="Verdana" size=2>The other day, someone posted a message at work asking for a way to find out the drive letter for partition 1 on the first disk.<br /><br />
The first response offered this:<br /><br /></font>
<font face="Courier New">C:&gt;echo list volume | diskpart<br />
Microsoft DiskPart version 5.1.3565<br />
<br />
Copyright (C) 1999-2003 Microsoft Corporation.<br />
<br />
On computer: SINISTAR<br />
<br />
DISKPART&gt;<br />
&nbsp;&nbsp;Volume&nbsp;###&nbsp;&nbsp;Ltr&nbsp;&nbsp;Label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Info<br />
&nbsp;&nbsp;----------&nbsp;&nbsp;---&nbsp;&nbsp;-----------&nbsp;&nbsp;-----&nbsp;&nbsp;----------&nbsp;&nbsp;-------&nbsp;&nbsp;---------&nbsp;&nbsp;--------<br />
&nbsp;&nbsp;Volume 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DVD-ROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 B<br />
&nbsp;&nbsp;Volume 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C&nbsp;&nbsp;&nbsp;BOOTDRIVE&nbsp;&nbsp;&nbsp;&nbsp;FAT32&nbsp;&nbsp;Partition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9 GB&nbsp;&nbsp;Healthy&nbsp;&nbsp;&nbsp;&nbsp;System<br />
&nbsp;&nbsp;Volume 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D&nbsp;&nbsp;&nbsp;Application&nbsp;&nbsp;NTFS&nbsp;&nbsp;&nbsp;Partition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15 GB&nbsp;&nbsp;Healthy&nbsp;&nbsp;&nbsp;&nbsp;Pagefile<br />
&nbsp;&nbsp;Volume 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E&nbsp;&nbsp;&nbsp;SharedAndUn&nbsp;&nbsp;NTFS&nbsp;&nbsp;&nbsp;Partition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10 GB&nbsp;&nbsp;Healthy<br />
<br />
DISKPART&gt;<br />
<br />
C:\&gt;<br/><br /></font>
<font face="Verdana" size=2>The original poster then asked if anyone already had a script to parse the output of diskpart.  I helpfully offered this:<br /><br /></font>
<font face="Courier New" size=2>@for /f "tokens=3" %%x in ('echo list volume ^| diskpart ^| findstr /c:"Volume %1"') do @echo %%x</font><br /><br />
<font face="Verdana" size=2>"How clever of me," thought I.  "Simply pass in a volume number and it neatly spits out the drive letter."  I was all proud of myself until someone pointed out that we already had a perfectly good .exe that did the same thing.<br />
<br />
The moral?  It's all fun and games 'til you find out you just reinvented the wheel...</font>]]></content:encoded>
    </item>
    <item>
      <title>Making your scripts look prettier</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/making-your-scripts-look-prettier</link>
      <pubDate>Fri, 30 Sep 2005 23:48:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/09/30/making-your-scripts-look-prettier/</guid>
      <description><![CDATA[Many languages provide a mechanism to make their code look pretty. VBScript, for example, assumes...]]></description>
      <content:encoded><![CDATA[<FONT face=Verdana size=2>Many languages provide a mechanism to make their code look pretty. VBScript, for example, assumes one statement per line, but including an underscore at the end of the line indicates that your statement continues on the next line.<BR><BR><U>Normal</U></FONT><BR><FONT face="Courier New" size=2>WScript.Echo "This is line one" &amp; vbcrlf&nbsp;&amp; "This is line two" &amp; vbcrlf &amp; "This is line three"</FONT><BR><BR><FONT face=Verdana size=2><U>With Line Continuation Characters</U></FONT><BR><FONT face="Courier New" size=2>WScript.Echo "This is line one" &amp; vbcrlf &amp; _ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "This is line two" &amp; vbcrlf &amp; _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "This is line three"<BR><BR></font><FONT face=Verdana size=2>It's much easier to tell what's going on in the second script.<BR><BR>In batch, you often see variables "built up" like this:</FONT><BR><BR><FONT face="Courier New" size=2>set MACHINENAMES=sinistar<BR>set MACHINENAMES=%MACHINENAMES% tempest<BR>set MACHINENAMES=%MACHINENAMES% joust</FONT><BR><BR><FONT face=Verdana size=2>...and in the end you have a variable with three items in it.<BR><BR>As it happens,&nbsp;you can take advantage of CMD's escape character, the carat, to make this a little easier to read:</FONT><BR><BR><FONT face="Courier New" size=2>set MACHINENAMES=sinistar^<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempest^<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;joust</FONT><BR><BR><font face="Verdana" size=2>And again you have a variable with three items in it.&nbsp; The second example does have one (largish) difference, though.&nbsp; Rather than <FONT face="Courier New" size=2>MACHINENAMES</FONT> being "sinistar tempest joust" (as in the first example), it will have "sinistar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; joust".&nbsp; If spacing is important to what you're doing, then by all means stick to the first way.&nbsp; However, if you're only building up a list to use in a <FONT face="Courier New" size=2>for</FONT> loop, the second will work just fine since <FONT face="Courier New" size=2>for</FONT> splits its arguments on one or more whitespace characters, so the following are equivalent:<BR><BR><FONT face="Courier New" size=2>for %x in (%MACHINENAMES%) do @echo %x<BR>for %x in (sinistar tempest joust) do @echo %x<BR>for %x in (sinistar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;joust) do @echo %x</FONT><BR><BR>Admittedly, I've only used this once or twice. Generally the lists I have to keep are pretty small, but on the occasions where I have very long lists, it can come in handy.</FONT>]]></content:encoded>
    </item>
    <item>
      <title>That's a pretty shifty argument...</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/thats-a-pretty-shifty-argument</link>
      <pubDate>Thu, 30 Jun 2005 16:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/06/30/thats-a-pretty-shifty-argument/</guid>
      <description><![CDATA[It's pretty easy to deal with up to 9 arguments in batch through built-in variables %1 through...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2>It's pretty easy to deal with up to 9 arguments in batch through built-in variables <FONT face="Courier New">%1</FONT> through <FONT face="Courier New">%9</FONT>.&nbsp; For </FONT><FONT face=Verdana size=2>example:</FONT></P>
<P><FONT size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; <U>echoargs.cmd</U><BR>&nbsp;&nbsp;&nbsp; @echo off<BR>&nbsp;&nbsp;&nbsp; echo %1<BR>&nbsp;&nbsp;&nbsp; echo %2<BR>&nbsp;&nbsp;&nbsp; echo %3<BR>&nbsp;&nbsp;&nbsp; echo %4<BR>&nbsp;&nbsp;&nbsp; echo %5<BR>&nbsp;&nbsp;&nbsp; echo %6<BR>&nbsp;&nbsp;&nbsp; echo %7<BR>&nbsp;&nbsp;&nbsp; echo %8<BR>&nbsp;&nbsp;&nbsp; echo %9</FONT></FONT></P>
<P><FONT face=Verdana size=2>If you feed this A B C D E F G H I, you'll get back those letters, one per line.</FONT></P>
<P><FONT face=Verdana size=2>But, if you try this with a tenth argument, it won't work like you might have thought:</FONT></P>
<P><FONT size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; <U>echo10args.cmd<BR></U>&nbsp;&nbsp;&nbsp; @echo off<BR>&nbsp;&nbsp;&nbsp; echo %1<BR>&nbsp;&nbsp;&nbsp; echo %2<BR>&nbsp;&nbsp;&nbsp; echo %3<BR>&nbsp;&nbsp;&nbsp; echo %4<BR>&nbsp;&nbsp;&nbsp; echo %5<BR>&nbsp;&nbsp;&nbsp; echo %6<BR>&nbsp;&nbsp;&nbsp; echo %7<BR>&nbsp;&nbsp;&nbsp; echo %8<BR>&nbsp;&nbsp;&nbsp; echo %9<BR>&nbsp;&nbsp;&nbsp; echo %10</FONT></FONT></P>
<P><FONT face=Verdana size=2>You'll see that the last line echoes the first argument again, followed by a 0 (<FONT face="Courier New">A0</FONT>).&nbsp; That is, it gets parsed as </FONT><FONT face=Verdana size=2>"echo %1, then 0".&nbsp; So, how do you deal with this if you need more than 9 arguments?&nbsp; My first suggestion </FONT><FONT face=Verdana size=2>would be to see if there's a way you can deal with fewer arguments, though that's often not possible.&nbsp; If </FONT><FONT face=Verdana size=2>you must, you'll need to loop over each argument and deal with them one by one.&nbsp; Here's an example </FONT><FONT face=Verdana size=2>listing:</FONT></P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; <U>echoallargs.cmd</U><BR>&nbsp;&nbsp;&nbsp; @echo off<BR></FONT><FONT face="Courier New" size=2></FONT><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; :Top</FONT><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; REM If there aren't any arguments to deal with, bail out<BR>&nbsp;&nbsp;&nbsp; if "%1" equ "" goto :NoMoreArgs</FONT><BR><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; call :EchoArg %1</FONT><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; shift</FONT><BR><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; REM Start the loop over again with a brand new %1<BR>&nbsp;&nbsp;&nbsp; goto :Top</FONT><BR><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; :NoMoreArgs<BR>&nbsp;&nbsp;&nbsp; echo No more arguments to deal with<BR>&nbsp;&nbsp;&nbsp; goto :EOF</FONT><BR><BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; :EchoArg<BR>&nbsp;&nbsp;&nbsp; echo Arg: %1<BR>&nbsp;&nbsp;&nbsp; goto :EOF</FONT><BR><BR><FONT face=Verdana size=2>Let's call this script with 11 arguments: <FONT face="Courier New">A B C D E F G H I J K</FONT></FONT> 
<P></P>
<P><FONT face=Verdana size=2>At <FONT face="Courier New">:Top</FONT>, we check to see if there are any arguments to deal with.&nbsp; If not, we go to :NoMoreArgs and bail </FONT><FONT face=Verdana size=2>out.&nbsp; Then (assuming we didn't bail out), we call <FONT face="Courier New">:EchoArg</FONT> with the parameter that's first in the list (in </FONT><FONT face=Verdana size=2>this case, <FONT face="Courier New">A</FONT>).&nbsp; <FONT face="Courier New">:EchoArg</FONT> takes the parameter it was passed (<FONT face="Courier New">A</FONT>) and echos <FONT face="Courier New">Arg: A</FONT>.&nbsp; Once it's done, we use </FONT><FONT face=Verdana size=2><FONT face="Courier New">goto :EOF</FONT> to indicate that we're done with this subroutine.&nbsp; Control then passes back up to the line </FONT><FONT face=Verdana size=2>just after our <FONT face="Courier New">call</FONT>.</FONT></P>
<P><FONT face=Verdana size=2>This next step is where all the magic happens.&nbsp; The <FONT face="Courier New">shift</FONT> command takes everything you've passed in and </FONT><FONT face=Verdana size=2>shifts them all to the left by one.&nbsp; That is, what used to be <FONT face="Courier New">%3</FONT> becomes <FONT face="Courier New">%2</FONT>, <FONT face="Courier New">%2</FONT> becomes <FONT face="Courier New">%1</FONT>, and <FONT face="Courier New">%1</FONT> falls </FONT><FONT face=Verdana size=2>off.&nbsp; So now, since there was a tenth parameter, that one becomes <FONT face="Courier New">%9</FONT>, which means there's now a way of </FONT><FONT face=Verdana size=2>referring to it.</FONT></P>
<P><FONT face=Verdana size=2>Once we've shifted everything, we go back to the <FONT face="Courier New">:Top</FONT> again.&nbsp; Now since our original second argument (B) </FONT><FONT face=Verdana><FONT size=2>has been shifted to <FONT face="Courier New">%1</FONT>, we do the same thing all over again.&nbsp; That gets echoed, we <FONT face="Courier New">shift</FONT> again, and <FONT face="Courier New">C</FONT> is </FONT><FONT size=2>the new <FONT face="Courier New">%1</FONT> (and K is the new <FONT face="Courier New">%9</FONT>).&nbsp; We keep doing this until we run out of arguments, and then we bail out.</FONT></FONT></P>
<P><FONT face=Verdana size=2>There are a few important points in here:</FONT></P>
<UL>
<LI><FONT face=Verdana size=2>For anything you call, whether it's a "subroutine" like <FONT face="Courier New">:EchoArg</FONT> or another script (like <FONT face="Courier New">call foo.cmd</FONT>), </FONT><FONT face=Verdana size=2>the arguments passed to it are "local".&nbsp; That is, if&nbsp;you were to call <FONT face="Courier New">:EchoArg %8</FONT> (that is, <FONT face="Courier New">H</FONT> in our case), </FONT><FONT face=Verdana size=2>as far as <FONT face="Courier New">:EchoArg</FONT> is concerned, that's <FONT face="Courier New">%1</FONT>.&nbsp; It's its own first argument.</FONT><FONT face=Verdana size=2> 
<LI>The built-in variable <FONT face="Courier New">%*</FONT> (meaning all arguments passed in) is not at all affected by <FONT face="Courier New">shift</FONT>.&nbsp; In our </FONT><FONT face=Verdana size=2>example, no matter how much you <FONT face="Courier New">shift</FONT>, <FONT face="Courier New">%*</FONT> will still be <FONT face="Courier New">A B C D E F G H I J K</FONT>.&nbsp; This is sort of </FONT><FONT face=Verdana size=2>unfortunate, in my opinion, since there are times that I've found that I wanted to deal with the first </FONT><FONT face=Verdana size=2>(say) three arguments, then refer to "the rest" in one fell swoop, but the only way to do that is <FONT face="Courier New">shift</FONT> </FONT><FONT face=Verdana size=2>your way through them one by one.</FONT></LI></UL>
<P><FONT face=Verdana size=2>While we're on the topic of <FONT face="Courier New">shift</FONT>, you can see from <FONT face="Courier New">shift /?</FONT> that it can also take a switch that indicates </FONT><FONT face=Verdana size=2>where you want to start shifting.&nbsp; This takes a bit of wrapping your brain around, but it goes like this:</FONT></P>
<P><FONT face=Verdana size=2>Given a list of arguments <FONT face="Courier New">A B C D E F G H I J K</FONT>, a regular shift would change that to <FONT face="Courier New">B C D E F G H I J K</FONT>. </FONT></P>
<P><FONT face=Verdana size=2>But, we could also use <FONT face="Courier New">shift /3</FONT> (for example) to start the shifting at the third argument.&nbsp; So our <FONT face="Courier New">A B C D </FONT></FONT><FONT face=Verdana size=2><FONT face="Courier New">E F G H I J K</FONT> becomes <FONT face="Courier New">A B D E F G H I J K</FONT>; the third argument (<FONT face="Courier New">C</FONT>) gets swallowed.&nbsp; Note that even though you </FONT><FONT face=Verdana size=2>can address 9 elements at a time <FONT face="Courier New">%1 </FONT><FONT face=Verdana>through <FONT face="Courier New">%9</FONT>, you can't do <FONT face="Courier New">shift /9</FONT> and have the tenth argument become the </FONT></FONT><FONT face=Verdana size=2>ninth.&nbsp; You're limited to <FONT face="Courier New">shift /8</FONT>.&nbsp; </FONT></P>
<P><FONT face=Verdana size=2>Oh well, you can't have everything...</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Ignoring the output of a command</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/ignoring-the-output-of-a-command</link>
      <pubDate>Wed, 08 Jun 2005 19:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/06/08/ignoring-the-output-of-a-command/</guid>
      <description><![CDATA[Earlier, I used &gt;nul 2&gt;&amp;1 to suppress the output of a command, and the question was...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2><a href="https://blogs.msdn.com:443/myocom/archive/2005/06/03/425062.aspx">Earlier</A>, I used <FONT face="Courier New">&gt;nul 2&gt;&amp;1</FONT> to suppress the output of a command, and the question was brought up as to why this was "better" than just <FONT face="Courier New">&gt;nul</FONT>.</FONT></P>
<P><FONT face=Verdana size=2>To understand what's going on, you need to know that there are two streams of output from any given command.&nbsp; There's <FONT face="Courier New">STDOUT</FONT> (or "standard out", or "standard output") and <FONT face="Courier New">STDERR</FONT> (or "standard error").&nbsp; Well-behaved executables will output error messages to <FONT face="Courier New">STDERR</FONT> and regular output to <FONT face="Courier New">STDOUT</FONT>.&nbsp; In <FONT face="Courier New">CMD</FONT> by default, both <FONT face="Courier New">STDOUT</FONT> and <FONT face="Courier New">STDERR</FONT> are echoed to the console.&nbsp; You can redirect this output by using <FONT face="Courier New">&gt;</FONT>.&nbsp; Typically this is done to redirect output to a file.&nbsp; However, this only redirects <FONT face="Courier New">STDOUT</FONT> to the file; <FONT face="Courier New">STDERR</FONT> will still display on the screen.</FONT></P>
<P><FONT face=Verdana size=2>On the command line, when redirecting output, 1 (or nothing) means <FONT face="Courier New">STDOUT</FONT> and 2 means <FONT face="Courier New">STDERR</FONT>.&nbsp; That is, <FONT face="Courier New">foo.exe &gt;foo.txt</FONT> redirects <FONT face="Courier New">foo.exe</FONT>'s <FONT face="Courier New">STDOUT</FONT> to <FONT face="Courier New">foo.txt</FONT>, and its <FONT face="Courier New">STDERR</FONT> (if any) will display on the screen.&nbsp; Running <FONT face="Courier New">foo.exe 1&gt;foo.txt</FONT> would do the same thing.&nbsp; To deal with <FONT face="Courier New">STDERR</FONT>, use <FONT face="Courier New">2&gt;</FONT>, as in <FONT face="Courier New">foo.exe 2&gt;foo.txt</FONT>.&nbsp; </FONT></P>
<P><FONT face=Verdana size=2>So, if you wanted <STRONG>all</STRONG> output from <FONT face="Courier New">foo.exe</FONT>, you could run <FONT face="Courier New">foo.exe &gt;foo.txt 2&gt;foo.txt</FONT>.&nbsp; As it happens, since that's a lot of typing, <FONT face="Courier New">CMD</FONT> has this little shortcut for tying one stream's redirection to another: <FONT face="Courier New">foo.exe &gt;foo.txt 2&gt;&amp;1</FONT> means "Run <FONT face="Courier New">foo.exe</FONT> and redirect its <FONT face="Courier New">STDOUT</FONT> to <FONT face="Courier New">foo.txt</FONT>, and redirect its <FONT face="Courier New">STDERR</FONT> to wherever <FONT face="Courier New">STDOUT</FONT> goes."</FONT></P>
<P><FONT face=Verdana size=2>This is all well and good for redirecting to files, but there are also some built-in "devices" which act like files.&nbsp; <FONT face="Courier New">NUL</FONT> is one such "device", which is used to just discard any output.&nbsp; So running <FONT face="Courier New">foo.exe &gt;nul 2&gt;&amp;1</FONT> would discard any and all output from <FONT face="Courier New">foo.exe</FONT>.&nbsp; Since devices act like files, you'll notice you can't create files that are the same name as a device.</FONT></P>
<P><FONT face=Verdana size=2>For those of you who are keeping score at home, other output devices off the top of my head include:</FONT></P>
<UL>
<LI><FONT face=Verdana size=2><FONT face="Courier New">LPT1, LPT2</FONT><FONT face=Verdana>,&nbsp;etc.&nbsp;</FONT>(parallel ports, usually used for Line PrinTers)</FONT></LI>
<LI><FONT face=Verdana size=2><FONT face="Courier New">COM1</FONT>, <FONT face="Courier New">COM2,<FONT face=Verdana> etc.,</FONT> </FONT>(serial ports)</FONT></LI>
<LI><FONT face=Verdana size=2><FONT face="Courier New">AUX</FONT> (auxilliary device - <FONT face="Courier New">COM1</FONT> by default)</FONT></LI>
<LI><FONT face=Verdana size=2><FONT face="Courier New">CON</FONT> (console - the default device, i.e., your screen)</FONT></LI>
<LI><FONT face=Verdana size=2><FONT face="Courier New">PRN</FONT> (printer - same as <FONT face="Courier New">LPT1</FONT>, though something in the back of my mind tells me there used to be a way to reassign this).</FONT></LI></UL>
<P><FONT face=Verdana size=1><STRONG>Edit</STRONG>: Reformatted for clarity.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Opening web pages from the command line</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/opening-web-pages-from-the-command-line</link>
      <pubDate>Tue, 07 Jun 2005 19:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/06/07/opening-web-pages-from-the-command-line/</guid>
      <description><![CDATA[I spend a lot of time in a CMD window.&nbsp; I mean a lot of time.&nbsp; Often I'd like to open a...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2>I spend a lot of time in a CMD window.&nbsp; I mean a <STRONG>lot</STRONG> of time.&nbsp; Often I'd like to open a web page, but opening up Internet Explorer and navigating my way to the page in question is such a chore.&nbsp; I'm lazy.&nbsp; I don't like mouse-clicks.&nbsp; Enter the quicky batch file.</FONT></P>
<P dir=ltr><FONT face=Verdana size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; <U>traffic.cmd</U> </FONT>- This checks my local traffic conditions (thanks to the excellent folks at the WSDOT)<BR></FONT><FONT size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; @start </FONT><A href="https://www.wsdot.wa.gov/Traffic/seattle/I405_53rd.htm"><FONT face="Courier New">https://www.wsdot.wa.gov/Traffic/seattle/I405_53rd.htm</FONT></A></FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P dir=ltr><FONT face=Verdana size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; <U>weather.cmd</U></FONT> - This tells me the current conditions in my area<BR></FONT><FONT size=2><FONT face="Courier New">&nbsp;&nbsp;&nbsp; @start </FONT><A href="https://www.weather.com/outlook/recreation/golf/local/98052"><FONT face="Courier New">https://www.weather.com/outlook/recreation/golf/local/98052</FONT></A></FONT></P>
<P><FONT face=Verdana size=2>You get the idea...</FONT></P>
<P><FONT face=Verdana size=1><STRONG>Edit</STRONG>: Changed inadvertant italics</FONT><FONT face=Verdana size=1></P></FONT>]]></content:encoded>
    </item>
    <item>
      <title>Backslashes vs. slashes - who knew?</title>
      <link>https://docs.microsoft.com/archive/blogs/myocom/backslashes-vs-slashes-who-knew</link>
      <pubDate>Tue, 07 Jun 2005 18:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Mark Yocom [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/myocom/2005/06/07/backslashes-vs-slashes-who-knew/</guid>
      <description><![CDATA[Here's something I'd never noticed until today, when I discovered it quite by accident.&nbsp; In...]]></description>
      <content:encoded><![CDATA[<P><FONT face=Verdana size=2>Here's something I'd never noticed until today, when I discovered it quite by accident.&nbsp; In general, to run a program in a different directory, you specify the path with backslashes, such as <FONT face="Courier New">C:\WINDOWS\system32\notepad.exe</FONT>.&nbsp; This should be no surprise.&nbsp; What <STRONG>is</STRONG> surprising, though, is that if you use call to run this, you can use forward slashes: <FONT face="Courier New">call C:/WINDOWS/system32/notepad.exe</FONT>.</FONT></P>
<P><FONT face=Verdana size=2>I'd love to know the reasoning behind this; it's not particularly useful unless you're a Linux guy who can't get out of the habit of using <FONT face="Courier New">/</FONT>.&nbsp; Even then, though,&nbsp;it's exceedingly unlikely that you'd precede everything with <FONT face="Courier New">call</FONT>.</FONT></P>]]></content:encoded>
    </item>
  </channel>
</rss>