<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>..::\\ www.christiano.ch //::.. &#187; CMD / Batch</title>
	<atom:link href="http://www.christiano.ch/wordpress/category/microsoft/cmd-batch/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christiano.ch/wordpress</link>
	<description>christiano.ch blog - personal knowledge base, news, memoires et cetera</description>
	<lastBuildDate>Fri, 06 Jan 2012 15:28:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<item>
		<title>Finding process that locks a DLL</title>
		<link>http://www.christiano.ch/wordpress/2011/09/04/finding-process-that-locks-a-dll/</link>
		<comments>http://www.christiano.ch/wordpress/2011/09/04/finding-process-that-locks-a-dll/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 06:15:08 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tips n'Tricks]]></category>
		<category><![CDATA[Windows General]]></category>
		<category><![CDATA[DLL]]></category>
		<category><![CDATA[Tasklist]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2011/09/04/finding-process-that-locks-a-dll/</guid>
		<description><![CDATA[You want to replace a dll on a system, but you get access denied, although you’re admin, have the necessary rights.. so which process is locking the particular file/library. I know, there is handles.exe from Sysinternal Suite, and plenty other &#8230; <a href="http://www.christiano.ch/wordpress/2011/09/04/finding-process-that-locks-a-dll/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="557">You want to replace a dll on a system, but you get access denied, although you’re admin, have the necessary rights.. so which process is locking the particular file/library. I know, there is handles.exe from Sysinternal Suite, and plenty other tools that do the trick.But, you don’t need third-party tools to get the answer, just use tasklist.exe or PowerShell.</td>
<td valign="top" width="117">&nbsp;</td>
</tr>
</tbody>
</table>
<p><span id="more-1254"></span>
<p>Windows command line:</p>
<pre>C:\&gt; tasklist /FI "modules eq vstoee.dll"</pre>
<p>PowerShell
<pre>PS C:\&gt; Get-Process | ? { $_.Modules -like "*(vstoee.dll)*" }</pre>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Finding+process+that+locks+a+DLL+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1254" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Finding+process+that+locks+a+DLL+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1254" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2011/09/04/finding-process-that-locks-a-dll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scan IP range using ping</title>
		<link>http://www.christiano.ch/wordpress/2011/07/16/scan-ip-range-using-ping/</link>
		<comments>http://www.christiano.ch/wordpress/2011/07/16/scan-ip-range-using-ping/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 15:35:44 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[IPScan]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2011/07/16/scan-ip-range-using-ping/</guid>
		<description><![CDATA[IP scanner for the poor ones Just open up a cmd.exe and change the ip range.. C:\&#62;FOR /L %x in (1,1,255) do ping -n 1 192.168.2.%x &#124; find /I &#34;reply&#34; &#62;&#62; c:\temp\pingresult.txt The above command uses a FOR loop to &#8230; <a href="http://www.christiano.ch/wordpress/2011/07/16/scan-ip-range-using-ping/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>IP scanner for the poor ones <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Zwinkerndes Smiley" src="http://www.christiano.ch/wordpress/wp-content/uploads/2011/07/wlEmoticon-winkingsmile.png" /></p>
<p>Just open up a cmd.exe and change the ip range..</p>
<blockquote><p>C:\&gt;FOR /L %x in (1,1,255) do ping -n 1 192.168.2.%x | find /I &quot;reply&quot; &gt;&gt; c:\temp\pingresult.txt</p>
</blockquote>
<p>The above command uses a FOR loop to ping each device and looks for &quot;Reply&quot; in the output. If there is a &quot;Reply&quot; then the host is up.. Results will be written to C:\temp\pingresults.txt</p>
<p>Or the PowerShell version: </p>
<blockquote><p>C:\&gt; 1..255 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send(&quot;192.168.2.$_&quot;) } | where-object {$_.Status -eq &quot;success&quot;} | select Address</p>
</blockquote>
<p><span id="more-1240"></span>
<p>Address    <br />&#8212;&#8212;-     <br />192.168.2.1     <br />192.168.2.5     <br />192.168.2.10     <br />192.168.2.11     <br />192.168.2.12</p>
<p>At first glance the results are very similar and you would think, &quot;Why all the extra typing? The second command is 2.5 times longer!&quot; The big difference between the standard windows command line and powershell is that the latter uses objects, which gives a lot of power&#8230;in our shell. Not let&#8217;s see how it works&#8230;</p>
<p>In the above command the range operator (..) generates a list of the numbers 1 through 255. The cool thing is you don&#8217;t have to use just a single range, you can string them together like this (1..5),7,(9..10) which would give you the numbers 1-10 skipping 6 and 8.</p>
<blockquote><p>foreach-object { (new-object System.Net.Networkinformation.Ping).Send(&quot;10.10.10.$_&quot;) }</p>
</blockquote>
<p>The foreach-object takes the numbers fed into the pipeline and operates on them one at a time. First, it creates a new ping object and then calls the send method. The parameter given to the send method is a string concatenation of 10.10.10. and the number from $_, which is the &quot;current pipeline object.&quot; The $_ variable in our example will contain the numbers 1-255.</p>
<blockquote><p>where-object {$_.Status -eq &quot;success&quot;}</p>
</blockquote>
<p>The output of the send method is the PingReply object which contains a status. We can filter the results only successful pings reply objects will be sent further down the pipeline.</p>
<blockquote><p>Select Address      <br />Finally, all we care about is the address so that is the only piece we have displayed.</p>
</blockquote>
<p>Now that we know how it works, let&#8217;s pimp out our powershell version.</p>
<p>First, we don&#8217;t have to just use a contiguous set of numbers. If we wanted to scan all ip address before 10.10.10.100, after 10.10.10.200 and 10.10.10.155 we could use this:    <br />(1..99),(200..255),155 | foreach-object &#8230;.     <br />We can use the results to feed into other commands. You can ping sweep an entire subnet and have it automatically do an nslookup, attempt to list the contents of the c$ share, and tell you that you are doing a good job (a little positive reinforcement never hurts).</p>
<blockquote><p>PS C:\&gt;1..255 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send(&quot;10.10.10.$_&quot;) } | where-object {$_.Status -eq &quot;success&quot;} | foreach-object { nslookup $_; gci &quot;\\$($_.Address)\c$&quot;; echo &quot;Good Job&quot; }</p>
</blockquote>
<p>The ping sweep can be sped up by setting a timeout value (in milliseconds). In the example below we set the timeout value to 100ms.</p>
<blockquote><p>&#8230; (new-object System.Net.Networkinformation.Ping).Send(&quot;10.10.10.$_&quot;, 100) &#8230;</p>
</blockquote>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Scan+IP+range+using+ping+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1240" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Scan+IP+range+using+ping+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1240" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2011/07/16/scan-ip-range-using-ping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Did you know about DiskShadow? Creating Shadow Copy from the command line</title>
		<link>http://www.christiano.ch/wordpress/2010/07/16/did-you-know-about-diskshadow-creating-shadow-copy-from-the-command-line/</link>
		<comments>http://www.christiano.ch/wordpress/2010/07/16/did-you-know-about-diskshadow-creating-shadow-copy-from-the-command-line/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 06:27:55 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows General]]></category>
		<category><![CDATA[DiskShadow]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/07/16/did-you-know-about-diskshadow-creating-shadow-copy-from-the-command-line/</guid>
		<description><![CDATA[This can be an alternative for taking a Snapshot in Hyper-V.. According to TechNet @Microsoft they state: DiskShadow.exe is a tool that exposes the functionality offered by the Volume Shadow Copy Service (VSS). By default, DiskShadow uses an interactive command &#8230; <a href="http://www.christiano.ch/wordpress/2010/07/16/did-you-know-about-diskshadow-creating-shadow-copy-from-the-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="690">This can be an alternative for taking a Snapshot in Hyper-V..         <br />According to TechNet @Microsoft they state: DiskShadow.exe is a tool that exposes the functionality offered by the Volume Shadow Copy Service (VSS). By default, DiskShadow uses an interactive command interpreter similar to that of DiskRAID or DiskPart. DiskShadow also includes a scriptable mode.</td>
<td valign="top" width="10"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/Logo_windowsserver2008hypervlogov_21.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_windows-server-2008-hyper-v-logo-v_2" border="0" alt="Logo_windows-server-2008-hyper-v-logo-v_2" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/Logo_windowsserver2008hypervlogov_2_thumb1.png" width="165" height="78" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-1053"></span>
<p><strong>Note</strong>: DiskShadow.exe is not supported on Windows Server 2003 / Windows Vista!</p>
<p>Here are the commands for diskshadow to back up the VHD using VSS (its kicks off vss inside the VM so the data is consistent)   </p>
<p>Go to cmd prompt:    </p>
<p><em>diskshadow.exe     <br />set context persistent      <br />add volume d: alias ddrive      <br />set verbose on      <br />create      <br />expose %ddrive% y:</em>    </p>
<p>This will take a VSS snapshop of my D drive (where my vhd lives) and then mounts it as drive letter Y: Now copy the contents of Y: to a safe place. When your done you can delete the snapshop and unmount Y:    <br />Delete Shadows Volume D:    <br /><em>     <br />unexpose y:</em></p>
<p>&#160;</p>
<p>The following sequence generates a shadow copy on volume D: that remains even after the end of the program but not on the file system as &quot;previous version&quot; is available. Theoretically, you could run this script periodically. </p>
<p><em>set context persistent     <br />begin backup      <br />add volume e:      <br />create      <br />end backup</em></p>
<p><em></em></p>
<p><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/DiskShadow_Create_Backup_Shadow.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DiskShadow_Create_Backup_Shadow" border="0" alt="DiskShadow_Create_Backup_Shadow" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/DiskShadow_Create_Backup_Shadow_thumb.png" width="666" height="561" /></a> </p>
<p><em></em></p>
<p>The Fact that shadow copies for this volume are in use can also be seen in explorer. Right-click the drive D: and go to <em>Shadow Copies</em></p>
<p><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/DiskShadow_ShowShadowsExplorerDriveProperties.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DiskShadow_ShowShadowsExplorerDriveProperties" border="0" alt="DiskShadow_ShowShadowsExplorerDriveProperties" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/07/DiskShadow_ShowShadowsExplorerDriveProperties_thumb.png" width="367" height="516" /></a> </p>
<p>&#160;</p>
<p>To list the shadow just use </p>
<p><em>List Shadows</em></p>
<p>and to expose a specific shadow</p>
<p><em>expose {ShadowCopyId} V:</em></p>
<p>don’t forget to discard / unexpose the drive when done!</p>
<p><em>unexpose V:</em></p>
<p><strong>Links</strong></p>
<p><a title="DiskShadow Documentation @Microsoft Technet" href="http://technet.microsoft.com/de-de/library/cc772172(WS.10).aspx" target="_blank">DiskShadow Documentation @Microsoft Technet</a></p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Did+you+know+about+DiskShadow%3F+Creating+Shadow+Copy+from+the+command+line+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1053" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Did+you+know+about+DiskShadow%3F+Creating+Shadow+Copy+from+the+command+line+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D1053" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/07/16/did-you-know-about-diskshadow-creating-shadow-copy-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CMD: Merge splitted files using copy command</title>
		<link>http://www.christiano.ch/wordpress/2010/02/19/cmd-merge-splitted-files-using-copy-command/</link>
		<comments>http://www.christiano.ch/wordpress/2010/02/19/cmd-merge-splitted-files-using-copy-command/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:38:45 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tips n'Tricks]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/02/19/cmd-merge-splitted-files-using-copy-command/</guid>
		<description><![CDATA[Need to merge two files like, let’s say Textfile1.txt and Textfile2.txt into one single file? Easy, just use the old copy command to achieve this. To coy the contents of text files do: copy file1.ext+file2.ext targetFile.ext this will work as &#8230; <a href="http://www.christiano.ch/wordpress/2010/02/19/cmd-merge-splitted-files-using-copy-command/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="579">Need to merge two files like, let’s say Textfile1.txt and Textfile2.txt into one single file? Easy, just use the old copy command to achieve this. </td>
<td valign="top" width="95"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_cmd.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_cmd" border="0" alt="Logo_cmd" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_cmd_thumb.png" width="160" height="135" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-857"></span>
<p>To coy the contents of text files do: </p>
<p><strong><em>copy file1.ext+file2.ext targetFile.ext</em></strong></p>
<p>this will work as long as the files are plain text files (no Ctrl-Z characters inside the files)</p>
<p>If you need to merge binary files like .exe, .zip or one of those HJSplit, GSplit or a similar program that splitted files.. they usually are numbered like file.001, file.002 and so on, then use the /b parameter</p>
<p><strong><em>copy /b file.001+file.002 file.bin</em></strong></p>
<p>here are the possible copy command switches:</p>
<p><em>Copies one or more files to another location. </em></p>
<p><em>COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]     <br />&#160;&#160;&#160;&#160; [+ source [/A | /B] [+ ...]] [destination [/A | /B]] </em></p>
<p><em>&#160; source&#160;&#160;&#160;&#160;&#160;&#160; Specifies the file or files to be copied.     <br />&#160; /A&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Indicates an ASCII text file.      <br /><strong>&#160; /B&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Indicates a binary file.</strong>      <br />&#160; /D&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Allow the destination file to be created decrypted      <br />&#160; destination&#160; Specifies the directory and/or filename for the new file(s).      <br />&#160; /V&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Verifies that new files are written correctly.      <br />&#160; /N&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uses short filename, if available, when copying a file with a      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; non-8dot3 name.      <br />&#160; /Y&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Suppresses prompting to confirm you want to overwrite an      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; existing destination file.      <br />&#160; /-Y&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Causes prompting to confirm you want to overwrite an      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; existing destination file.      <br />&#160; /Z&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Copies networked files in restartable mode.      <br />&#160; /L&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; If the source is a symbolic link, copy the link to the target      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; instead of the actual file the source link points to. </em></p>
<p><em>The switch /Y may be preset in the COPYCMD environment variable.     <br />This may be overridden with /-Y on the command line.&#160; Default is      <br />to prompt on overwrites unless COPY command is being executed from      <br />within a batch script. </em></p>
<p><em>To append files, specify a single file for destination, but multiple files     <br />for source (using wildcards or file1+file2+file3 format).</em></p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=CMD%3A+Merge+splitted+files+using+copy+command+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D857" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=CMD%3A+Merge+splitted+files+using+copy+command+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D857" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/02/19/cmd-merge-splitted-files-using-copy-command/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CMD: Search and copy specific files on your computer</title>
		<link>http://www.christiano.ch/wordpress/2009/12/06/cmd-search-and-copy-specific-files-on-your-computer/</link>
		<comments>http://www.christiano.ch/wordpress/2009/12/06/cmd-search-and-copy-specific-files-on-your-computer/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 14:25:43 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2009/12/06/cmd-search-and-copy-specific-files-on-your-computer/</guid>
		<description><![CDATA[Okay, i just had to search for specific files on my computer and i wanted to have them copied to a specific folder. This is some kind of note for myself but maybe you can make use of it too &#8230; <a href="http://www.christiano.ch/wordpress/2009/12/06/cmd-search-and-copy-specific-files-on-your-computer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="680">Okay, i just had to search for specific files on my computer and i wanted to have them copied to a specific folder. This is some kind of note for myself but maybe you can make use of it too .. don’t know.</td>
<td valign="top" width="10"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2009/12/Logo_cmd.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_cmd" border="0" alt="Logo_cmd" src="http://www.christiano.ch/wordpress/wp-content/uploads/2009/12/Logo_cmd_thumb.png" width="150" height="126" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-818"></span>
<p>c:\&gt;FOR /F &quot;Tokens=*&quot; %i in (&#8216;DIR /B /S *map*.png&#8217;) do md &quot;c:\temp\icons\map%~pi   <br />&quot; | copy &quot;%i&quot; &quot;c:\temp\icons\map%~pi&quot;</p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=CMD%3A+Search+and+copy+specific+files+on+your+computer+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D818" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=CMD%3A+Search+and+copy+specific+files+on+your+computer+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D818" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2009/12/06/cmd-search-and-copy-specific-files-on-your-computer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FAQ &#8211; Windows Command Processor cmd.exe</title>
		<link>http://www.christiano.ch/wordpress/2009/10/29/faq-windows-command-processor-cmd-exe/</link>
		<comments>http://www.christiano.ch/wordpress/2009/10/29/faq-windows-command-processor-cmd-exe/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 11:09:56 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[CMD / Batch]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2009/10/29/faq-windows-command-processor-cmd-exe/</guid>
		<description><![CDATA[Ok, everybody talks and writes about Microsoft PowerShell .. BUT, what about those legacy systems that do NOT support the installation of PowerShell? Some, probably the majority know exactly what i’m talking about. Well, for sake of christ, there is &#8230; <a href="http://www.christiano.ch/wordpress/2009/10/29/faq-windows-command-processor-cmd-exe/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="451">Ok, everybody talks and writes about Microsoft PowerShell .. BUT, what about those legacy systems that do NOT support the installation of PowerShell? Some, probably the majority know exactly what i’m talking about. Well, for sake of christ, there is still another type of shell called cmd.exe and batchfiles (*.bat and *.cmd) to run some administrative tasks.. This article will show some possibilities about the command processer which is included in almost any Microsoft Windows Operating Systems – including Windows 7! <img src='http://www.christiano.ch/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </td>
<td valign="top" width="223"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2009/10/Logo_cmd1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_cmd" border="0" alt="Logo_cmd" src="http://www.christiano.ch/wordpress/wp-content/uploads/2009/10/Logo_cmd_thumb1.png" width="240" height="202" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-715"></span><br />
<h1>Frequently Asked Questions Regarding The Windows Command Processor</h1>
<table>
<tbody>
<tr>
<td>&#160;<br />
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="2"><font class="head3" size="2" face="arial, helvetica"><b class="bold">Topics on this Page</b> </font></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
<tr>
<td bgcolor="#ffffff" colspan="2"><img src="../images/spacer.gif" width="1" height="2" /></td>
</tr>
<tr><!--left column-->
<td valign="top" width="50%" align="left"><font size="2" face="arial,helvetica"><a href="#a" target="_self">What is the Windows 2000 Command Processor?</a>                     <br /><a href="#b" target="_self">How do I get help on commands?</a>                     <br /><a href="#c" target="_self">How do I create a file name or folder name using the current date (YYYYMMDD)?</a>                     <br /><a href="#d" target="_self">What environment variables are available to CMD.EXE?</a>                     <br /><a href="#e" target="_self">What switches are available for running Regedit.exe at a CMD prompt or in a batch file?</a>                     <br /><a href="#f" target="_self">How can I delete a Key or Value Name using a filename.reg file?</a>                     <br /><a href="#g" target="_self">What other tools are available for using the registry in batch?</a>                     <br /><a href="#h" target="_self">What commands can I use in a logon script?</a>                     <br /><a href="#i" target="_self">How can I perform a procedure on all files in a folder?</a>                     <br /><a href="#j" target="_self">How do I parse a file name parameter into its&#8217; constituent parts?</a>                     <br /><a href="#k" target="_self">How do I perform calculations?</a>                     <br /><a href="#l" target="_self">How do I test / manipulate strings?</a>                     <br /><a href="#m" target="_self">How do I read a file and process the lines of text?</a>                     <br /><a href="#n" target="_self">How do I launch a process at a different priority?</a>                     <br /><a href="#o" target="_self">How do I display the current directory in the Title bar of a batch files command Windows?</a>                     <br /><a href="#p" target="_self">How can a batch file alter the size of its&#8217; CMD Window?</a>                     <br /><a href="#q" target="_self">How can I get a batch file to prompt for user input?</a>                     <br /><a href="#r" target="_self">How can I get a batch file to &#8216;sleep&#8217; for n seconds?</a>                     <br /><a href="#s" target="_self">How can I get a batch file to beep for attention?</a>                     <br /><a href="#t" target="_self">How do I pipe batch output, including commands and responses, to a log file?</a>                     <br /><a href="#u" target="_self">What is delayed environment variable expansion?</a>                     <br /><a href="#v" target="_self">What are the conditional processing symbols?</a>                     <br /><a href="#w" target="_self">How do I send a pop-up message?</a>                     <br /><a href="#x" target="_self">How do I execute a command in every sub-folder?</a>                     <br /><a href="#y" target="_self">How do I remove all files and sub-directories from a folder, without removing the folder?</a>                     <br /><a href="#z" target="_self">How can I send e-mail from a batch script?</a>                     <br /><a href="#aa" target="_self">How can I retrieve basic user data?</a>                     <br /><a href="#ab" target="_self">How can I count the number of lines in a file, and/or display the last n lines? </a>                    <br /><a href="#ac" target="_self">How can I create a file containing all the user names in my domain?</a>                     <br /><a href="#ad" target="_self">&#8216;&lt;Command&gt;&#8217; is not recognized as an internal or external command, operable program or batch file?</a>                     <br />&#160;</font></td>
</tr>
<tr>
<td bgcolor="#ffffff" colspan="2"><img src="../images/spacer.gif" width="1" height="2" /></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What is the Windows 2000 Command Processor? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: Windows 2000 supports two (2) command processors: </p>
<p>- COMMAND.COM is the command processor for the <b>v</b>irtual <b>D</b>OS <b>M</b>achine (<b>VDM</b>), used for processing MS-DOS based applications and scripts. </p>
<p>- CMD.EXE is the native 32-bit command processor, used to open a command prompt and to press batch (.bat) files. </p>
<p>This FAQ addresses CMD.EXE. If you need help troubleshooting 16-bit applications, see Microsoft Knowledge Base articles: </p>
<p><a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q196453&amp;sd=tech">Troubleshooting NTVDM and WOW Startup Errors (Q196453)</a>. </p>
<p><a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q165214&amp;sd=tech.">Troubleshooting MS-DOS-Based Programs in Windows (Q165214)</a> </p>
<p><a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q103656&amp;sd=tech">Troubleshooting 16-Bit Windows Applications (Q103656)</a>. </p>
<p><b>To identify whether any program is 16-bit or 32-bit:</b> </p>
<ol>
<li>Use Windows Explorer to navigate to the folder that contains the executable (.exe) file. </li>
<li>Right-click the .exe file and press <b>Properties</b>. </li>
<li>The program is probably 16-bit if there is no <b>Version</b> tab. To be sure, create a shortcut from the .exe file. If the shortcut <b>Properties</b> has a <b>Run in separate memory space</b> check box, it is 16-bit. </li>
</ol>
<p><b>To identify whether a running program is 16-bit or 32-bit:</b> </p>
<ol>
<li>Right-click a blank area of the taskbar and press <b>Task Manager</b>. </li>
<li>Select the <b>Processes</b> tab. </li>
<li>Locate the program in the <b>Image Name</b> column. </li>
<li>16-bit programs run under the <b>v</b>irtual <b>D</b>OS <b>M</b>achine (<b>VDM</b>). The program is indented under Ntvdm.exe. Additionally, a 16-bit Windows program has wowexec.exe indented with it. This is the <b>W</b>indows <b>O</b>n <b>W</b>indows (<b>WOW</b>) emulator. </li>
</ol>
<p> <!--begin bookmark heading-->
<p><a name="b"></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I get help on commands? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: To get help on commands, open a CMD.EXE prompt and type any of the following: </p>
<p><b>help</b> &#8211; To get a list of supported commands. </p>
<p><b>&lt;Command Name&gt; /?</b> &#8211; to get help on <b>&lt;Command Name&gt;</b>. Example: <b>net /?</b> </p>
<p><b>&lt;Command Name&gt; &lt;Sub Command Name&gt; /?</b> &#8211; to get help on the <b>&lt;Command Name&gt; &lt;Sub Command Name&gt;</b>. Example: <b>net user /?</b> </p>
<p>Some commands provide detail help, such as <b>DIR</b>, <b>SET</b>, <b>FOR</b>, <b>IF</b>, etc., while others only provide minimal information, such as <b>NET USER</b>. To get additional help, create a shortcut to a <b>ntcmds.bat</b> file that contains: </p>
<p>@echo off            <br />start hh.exe ms-its:%WINDIR%\Help\windows.chm::/ntcmds.htm             <br />exit </p>
<p>and set it to run <b>Minimized</b>. <!--begin bookmark heading--></p>
<p><a name="c"></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I create a file name or folder name using the current date (YYYYMMDD)? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer. To parse the date into its&#8217; <b>YYYY</b>, <b>MM</b>, and <b>DD</b> components, we would use the <b>FOR</b> command. When you type <b>Date /T</b>, a typical North American installation would display <b>Day MM/DD/YYYY</b>, like <b>Mon 07/15/2002</b>. </p>
<p>To parse this into the <b>YYYY</b>, <b>MM</b>, and <b>DD</b> components, type: </p>
<p><b>for /f &quot;Tokens=2-4 Delims=/ &quot; %a in (&#8216;date /t&#8217;) do set mm=%a&amp;set dd=%b&amp;set yy=%c</b> </p>
<p><b>Note </b>When using the <b>FOR</b> command in a batch file, replace <b>%</b> with <b>%%</b>. </p>
<p>To create a folder named 20020715, type <b>MD %yy%%mm%%dd%</b>. </p>
<p>To create a universal date parser, that works on all Windows NT-based systems (Windows NT 4.0, Windows NT 5.0 (Windows 2000), and Windows NT 5.1 (Windows XP, which doesn&#8217;t display the <b>Day</b> when using <b>date /t</b>), regardless of date format, we can make use of the fact that when you type <b>Date</b>, a display similar to: </p>
<p><b>The current date is: Mon 07/15/2002              <br />Enter the new date: (mm-dd-yy)</b> </p>
<p>exhibits the format (<b>mm-dd-yy</b>). Create a batch file, named <b>univdate.bat</b>, in your path, which contains: </p>
<p><code>@echo off              <br />set $tok=1-3               <br />for /f &quot;tokens=1 delims=.:/-, &quot; %%u in ('date /t') do set $d1=%%u               <br />if &quot;%$d1:~0,1%&quot; GTR &quot;9&quot; set $tok=2-4               <br />for /f &quot;tokens=%$tok% delims=.:/-, &quot; %%u in ('date /t') do (               <br />for /f &quot;skip=1 tokens=2-4 delims=/-,().&quot; %%x in ('echo.^|date') do (               <br />set %%x=%%u               <br />set %%y=%%v               <br />set %%z=%%w               <br />set $d1=               <br />set $tok=))               <br />&#160;</code></p>
<p>When you type <b>call univdate</b>, the appropriate environment variables are set. In North America, this would typically be <b>mm</b>, <b>dd</b>, and <b>yy</b>. <!--begin bookmark heading--></p>
<p><a name="d"></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What environment variables are available to CMD.EXE? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: In addition to the environment variables that are defined using <b>Control Panel / System / Advanced / Environment Variables</b>, Windows 2000 has some built-in variables. To see the environment variables that are available, type <b>SET</b>. </p>
<p><b>Note </b>The built-in variables are different if you log on locally versus log on to a domain. Notice that <b>%LOGONSERVER%</b> contains the validating domain controller. </p>
<p>Windows 2000 also defines some hidden environment variables that you can use: </p>
<div class="tablediv">
<table class="dtTABLE" border="1" cellspacing="0">
<tbody>
<tr>
<th width="36%" align="left">Variable                    <br />&#160;</th>
<th width="64%" align="left">Description                    <br />&#160;</th>
</tr>
<tr>
<td valign="top" width="36%"><b>%CD%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the current directory. If your current folder is %USERPROFILE%\My Documents, @echo %CD% might display C:\Documents and Settings\Jerry\My Documents.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%DATE%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the same output as typing DATE.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%TIME%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the same output as typing TIME.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%RANDOM%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Generates a random integer in the range of 0 &#8211; 32767.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%ERRORLEVEL%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the current ERRORLEVEL.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%CMDEXTVERSION%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the current Command Processor Extensions version number.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="36%"><b>%CMDCMDLINE%</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="64%">Expands to the original command line that invoked the Command Processor.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
</tbody>
</table></div>
<p> <!--begin bookmark heading-->
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What switches are available for running Regedit.exe at a CMD prompt or in a batch file? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The Windows NT-based Registry Editor, Regedt32.exe, does <b>NOT</b> support batch or command prompt operations. You can use Regedit.exe, with appropriate switches, to silently <b>Merge</b> a filename.reg file with your registry, or to export a registry file. </p>
<p>To silently <b>Merge</b> a filename.reg file, use the following syntax: </p>
<p>regedit /s &lt;Drive:&gt;\FolderName\FileName.reg </p>
<p>To export a filename.reg file, in Windows NT 5.x format, use: </p>
<p>regedit /e &quot;&lt;Drive:&gt;\FolderName\FileName.reg&quot; &quot;KeyPath&quot; </p>
<p><b>Note </b>The quote marks are only required if the &#8216;path&#8217; contains spaces. </p>
<p>To export a filename.reg file, in W9x/NT4 format, suitable for merging with W9x/NT4/NT5 registries, use: </p>
<p>regedit /a &quot;&lt;Drive:&gt;\FolderName\FileName.reg&quot; &quot;KeyPath&quot; <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I delete a Key or Value Name using a filename.reg file? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: To delete a key, using a filename.reg file, use the following syntax: </p>
<p>REGEDIT4 </p>
<p>[-keyPath] </p>
<p>Example: To delete the <b>HKEY_LOCAL_MACHINE \Software \McAfee</b> Key, including all sub-keys, and all Value Names, use the following filename.reg file: </p>
<p>REGEDIT4 </p>
<p>[-HKEY_LOCAL_MACHINE \Software \McAfee] </p>
<p>Then run: </p>
<p>regedit /s &lt;Drive:&gt;\Folder\FileName.reg </p>
<p>To delete a Value Name, using a filename.reg file, use the following syntax: </p>
<p>REGEDIT4 </p>
<p>[keyPath]            <br />&quot;ValueName&quot;=- </p>
<p>Example: To delete the <b>Tweak UI</b> Value Name from the <b>HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \Windows \CurrentVersion \Run</b> key, use the following filename.reg file: </p>
<p>REGEDIT4 </p>
<p>[HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \Windows \CurrentVersion \Run]            <br />&quot;Tweak UI&quot;=- <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What other tools are available for using the registry in batch? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: If you install the Support Tools from the Windows 2000 CD-ROM, you can use REG.EXE to Add, Delete, Copy, Compare, Export, Import, Load a Hive, Query, Save, Restore, and Unload a Hive. To install the Support Tools: </p>
<ol>
<li>Insert the Windows 2000 CD-ROM into your CD-ROM drive. </li>
<li>Click <b>Browse this CD</b>, and then open the <b>Support\Tools</b> folder. </li>
<li>Double-click <b>Setup.exe</b>, and follow the on-screen instructions. </li>
</ol>
<p>Using REG.EXE, and Netdom.exe from the Support Tools, you can script a report of all the Windows NT-based workstations in your domain, listing the computer name, O/S version, and service pack, and piping the report to C:\report.txt: </p>
<p><code>@echo off              <br />setlocal               <br />if exist c:\report.txt del /q c:\report.txt               <br />For /f &quot;Skip=1 Tokens=1&quot; %%a in ('netdom query /domain WORKSTATION') do call :computer &quot;%%a&quot;               <br />endlocal               <br />goto :EOF               <br />:computer               <br />set machine=%1               <br />set machine=%machine:&quot;=%               <br />set cv=               <br />set CSD=               <br />if &quot;%machine%&quot; EQU &quot;The&quot; goto :EOF               <br />if &quot;%machine%&quot; EQU &quot;Directory&quot; goto :EOF               <br />for /f &quot;Skip=3 Tokens=2*&quot; %%i in ('reg QUERY &quot;\\%machine%\HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \Windows NT\CurrentVersion&quot; /v CurrentVersion') do set cv=%%j               <br />if not defined cv goto :EOF               <br />if &quot;%cv%&quot; LSS &quot;4.0&quot; goto :EOF               <br />for /f &quot;Skip=3 Tokens=2*&quot; %%i in ('reg QUERY &quot;\\%machine%\HKEY_LOCAL_MACHINE \SOFTWARE \Microsoft \Windows NT\CurrentVersion&quot; /v CSDVersion') do set csd=%%j               <br />@echo %machine% %cv% %csd%&gt;&gt;c:\report.txt               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What commands can I use in a logon script? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: A logon script can use any command supported by the client O/S. </p>
<p>If you have a mixture of Windows NT-based clients and other Windows clients, you can test if the client platform is Windows NT-based by including the following statement: </p>
<p>if &quot;%OS%&quot;==&quot;Windows_NT&quot; goto winnt </p>
<p>If you need to test for a specific operation system, the following commands should work on all Microsoft operating systems: </p>
<p><code>ver | find &quot;Windows XP&quot; &gt;nul              <br />if not errorlevel 1 goto WXP               <br />ver | find &quot;Windows 2000&quot; &gt;nul               <br />if not errorlevel 1 goto W2000               <br />ver | find &quot;Windows NT&quot; &gt;nul               <br />if not errorlevel 1 goto WNT               <br />ver | find &quot;Windows 98&quot; &gt;nul               <br />if not errorlevel 1 goto W98               <br />ver | find &quot;Windows 95&quot; &gt;nul               <br />if not errorlevel 1 goto W95               <br />ver | find &quot;Windows ME&quot; &gt;nul               <br />if not errorlevel 1 goto WME               <br />ver | find &quot;OEM Service Release&quot; &gt;nul               <br />if not errorlevel 1 goto WOEM               <br />ver | find &quot;MS-DOS&quot; &gt;nul               <br />if not errorlevel 1 goto DOS               <br />::Unknown               <br />echo ERROR - What are you running?               <br />goto END               <br />:WXP               </p>
<p>goto end               <br />:W2000               </p>
<p>goto end               <br />:WNT               </p>
<p>goto end               <br />:W98               </p>
<p>goto end               <br />:w95               </p>
<p>goto end               <br />:WME               </p>
<p>goto end               <br />:WOEM               </p>
<p>goto end               <br /> <img src='http://www.christiano.ch/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> OS               </p>
<p>:end               <br />&#160;</code></p>
<p>To define the <b>%USERNAME%</b>, <b>%COMPUTERNAME%</b>, and <b>%LOGONSERVER%</b> environment variables on non-Windows NT-based Windows clients, install <u>putinenv.exe </u>on all non-Windows NT-based Windows clients. You must also install WINSET.EXE, from the Windows CD-ROM, on these clients. You can then use the following code in your logon script: </p>
<p><code>if &quot;%OS%&quot;==&quot;Windows_NT&quot; goto winnt              <br />%windir%\putinenv.exe L               <br />%LogonServer%\NetLogon\Winset USERNAME=%USERNAME%               <br />%LogonServer%\NetLogon\Winset COMPUTERNAME=%COMPUTERNAME%               <br />%LogonServer%\NetLogon\Winset LOGONSERVER=%LOGONSERVER%               <br />:winnt               <br />&#160;</code></p>
<p>The most used command in a logon script is <b>net use</b>, used for mapping a drive letter to a share. The syntax is: </p>
<p><b>net use &lt;:Drive:&gt; \\ServerName\ShareName[\folder] /persistent:NO</b> </p>
<p><b>Note </b>See the <b>NET USE</b> help in the <b>ntcmds.chm</b> file for other options. Windows 2000 can map below a share, but downlevel clients cannot. If you have configured the users home directory, you can use the <b>net use &lt;:Drive:&gt; /home /persistent:NO</b> syntax. <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I perform a procedure on all files in a folder? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The <b>FOR</b> command will allow us to process multiple lines of command output. We can use the <b>FOR</b> command to pass the results of a <b>DIR</b> to a process. </p>
<p>If we wanted to rename all <b>.txt</b> files in a folder, whose 2nd-4th character of the file name was upper case ABC, to a <b>.log</b> file, we could use the following <b>example.bat</b> file, and pass the folder name as a parameter (<b>example.bat &quot;C:\Documents and Settings\Jerry\My Documents&quot;</b>) </p>
<p><code>@echo off              <br />setlocal               <br />if {%1}=={} goto syntax               <br />if not exist %1 goto syntax               <br />set folder=%1               <br />::Set folder as current directory               <br />pushd %1               <br />::Strip quote marks               <br />set folder=%folder:&quot;=%               <br />for /f &quot;Tokens=*&quot; %%a in ('dir /b /a-d &quot;%folder%\*.txt&quot;') do call :isabc &quot;%%a&quot;               <br />::Return to previous current directory               <br />popd               <br />endlocal               <br />goto :EOF               <br />:syntax               <br />@echo Syntax: Example FolderPath               <br />endlocal               <br />goto :EOF               <br />:isabc               <br />set filename=%1               <br />::Strip quote marks               <br />set filename=%filename:&quot;=%               <br />::Test 2nd position, for a 3 byte string               <br />if not &quot;%filename:~1,3%&quot; EQU &quot;ABC&quot; goto :EOF               <br />rename %1 *.log               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I parse a file name parameter into its&#8217; constituent parts? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: When you invoke a batch file with a parameter (%1), you are able to parse it to extract meaningful information. </p>
<p><b>Note </b>Command Extensions ( <b>/E:ON</b> ), enabled by default, must be on. </p>
<div class="tablediv">
<table class="dtTABLE" border="1" cellspacing="0">
<tbody>
<tr>
<th width="16%" align="left">Parameter                    <br />&#160;</th>
<th width="84%" align="left">Description                    <br />&#160;</th>
</tr>
<tr>
<td valign="top" width="16%">%1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">The normal parameter.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~f1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">expands %1 to a fully qualified path name.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~d1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">expands %1 to a drive letter only.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~p1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">expands %1 to a path only.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~n1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">expands %1 to a file name only (prefix)                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~x1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">expands %1 to a file extension only.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="16%">%~s1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="84%">changes the meaning of n and x options to reference the short name.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
</tbody>
</table></div>
<p>You can use these modifiers in combination: </p>
<div class="tablediv">
<table class="dtTABLE" border="1" cellspacing="0">
<tbody>
<tr>
<th width="21%" align="left">Parameter                    <br />&#160;</th>
<th width="79%" align="left">Description                    <br />&#160;</th>
</tr>
<tr>
<td valign="top" width="21%">%~dp1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="79%">expands %1 to a drive letter and path only.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="21%">%~nx1                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="79%">expands %1 to a file name and extension only.                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
</tbody>
</table></div>
<p>To determine where a batch file was run from, use %~dp0 </p>
<p>I have scripted <b>demo.bat</b> to display the various parsing of a file/folder name parameter. <b>Demo.bat</b> contains: </p>
<p><code>@echo off              <br />@echo Batch file: %~dp0               <br />If {%1}=={} @echo No parameter specified&amp;goto :EOF               <br />:loop               <br />If {%1}=={} goto :EOF               <br />@echo.               <br />@echo ^%%1=%1               <br />@echo ^%%~f1=%~f1               <br />@echo ^%%~d1=%~d1               <br />@echo ^%%~p1=%~p1               <br />@echo ^%%~n1=%~n1               <br />@echo ^%%~x1=%~x1               <br />@echo ^%%~s1=%~s1               <br />@echo ^%%~dp1=%~dp1               <br />@echo ^%%~nx1=%~nx1               <br />::Shift parameter string               <br />shift               <br />goto :loop               <br />&#160;</code></p>
<p>If I type: </p>
<p><code><b>demo &quot;C:\Documents and Settings\Jerry\My Documents\My Pictures\Jerold.jpg&quot;                <br />%SystemRoot%\Notepad.exe &quot;%userprofile%&quot;</b>               <br />&#160;</code></p>
<p><b><font face="courier">demo.bat</font></b> will display: </p>
<p><code>Batch file: C:\Util\              </p>
<p>%1=&quot;C:\Documents and Settings\Jerry\My Documents\My Pictures\Jerold.jpg&quot;               <br />%~f1=C:\Documents and Settings\Jerry\My Documents\My Pictures\Jerold.jpg               <br />%~d1=C:               <br />%~p1=\Documents and Settings\Jerry\My Documents\My Pictures\               <br />%~n1=Jerold               <br />%~x1=.jpg               <br />%~s1=C:\DOCUME~1\Jerry\MYDOCU~1\MYPICT~1\Jerold.jpg               <br />%~dp1=C:\Documents and Settings\Jerry\My Documents\My Pictures\               <br />%~nx1=Jerold.jpg               </p>
<p>%1=C:\WINNT\Notepad.exe               <br />%~f1=C:\WINNT\notepad.exe               <br />%~d1=C:               <br />%~p1=\WINNT\               <br />%~n1=notepad               <br />%~x1=.exe               <br />%~s1=C:\WINNT\notepad.exe               <br />%~dp1=C:\WINNT\               <br />%~nx1=notepad.exe               </p>
<p>%1=&quot;C:\Documents and Settings\Jerry&quot;               <br />%~f1=C:\Documents and Settings\Jerry               <br />%~d1=C:               <br />%~p1=\Documents and Settings\               <br />%~n1=Jerry               <br />%~x1=               <br />%~s1=C:\DOCUME~1\Jerry               <br />%~dp1=C:\Documents and Settings\               <br />%~nx1=Jerry               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I perform calculations? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The <b>SET</b> command can perform calculations. When you type <b>SET /?</b>, part of the help display contains: </p>
<p>&quot;The /A switch specifies that the string to the right of the equal sign is a numerical expression that is evaluated. The expression evaluator is pretty simple and supports the following operations, in decreasing order of precedence: </p>
<p><code>() - grouping              <br />* / % - arithmetic operators               <br />+ - - arithmetic operators               <br />&lt;&lt; &gt;&gt; - logical shift               <br />&amp; - bitwise and               <br />^ - bitwise exclusive or               <br />| - bitwise or               <br />= *= /= %= += -= - assignment               <br />&amp;= ^= |= &lt;&lt;= &gt;&gt;=               <br />, - expression separator               <br />&#160;</code></p>
<p>If you use any of the logical or modulus operators, you will need to enclose the expression string in quotes. Any non-numeric strings in the expression are treated as environment variable names whose values are converted to numbers before using them. If an environment variable name is specified but is not defined in the current environment, then a value of zero is used. This allows you to do arithmetic with environment variable values without having to type all those % signs to get their values. If SET /A is executed from the command line outside of a command script, then it displays the final value of the expression. The assignment operator requires an environment variable name to the left of the assignment operator. Numeric values are decimal numbers, unless prefixed by 0x for hexadecimal numbers, and 0 for octal numbers. So 0&#215;12 is the same as 18 is the same as 022. Please note that the octal notation can be confusing: 08 and 09 are not valid numbers because 8 and 9 are not valid octal digits.&quot; </p>
<p>We can script <b>Yesterday.bat</b> to calculate yesterdays date, returning the <b>PDMM</b>, <b>PDDD</b>, and <b>PDYY</b> environment variables: </p>
<p><code>@echo off              <br />call univdate               <br />::Force non-leading zero, as it may cause failure               <br />set /a PDDD=1%DD% - 101               <br />set /a PDMM=1%MM% - 100               <br />set /a PDYY=%YY%               <br />if %PDDD% GTR 0 goto return               <br />set /a PDMM=%PDMM% - 1               <br />if %PDMM% GTR 0 goto isleap               <br />set /a PDDD=31               <br />set /a PDMM=12               <br />set /a PDYY=%PDYY% - 1               <br />goto return               <br />:isleap               <br />if not %PDMM% EQU 2 goto days%PDMM%               <br />::Temporarily use PDDD as a work field               <br />set /a PDDD=%PDYY% / 4               <br />set /a PDDD=%PDDD% * 4               <br />if %PDDD% EQU %PDYY% goto leap               <br />set /a PDDD=28               <br />goto return               <br />:leap               <br />set /a PDDD=29               <br />goto return               <br />:days1               <br />:days3               <br />:days5               <br />:days7               <br />:days8               <br />:days10               <br />set /a PDDD=31               <br />goto return               <br />:days4               <br />:days6               <br />:days9               <br />:days11               <br />set /a PDDD=30               <br />:return               <br />::Force leading zero when day or month is single digit               <br />set /a PDDD=%PDDD% + 100               <br />set PDDD=%PDDD:~1,2%               <br />set /a PDMM=%PDMM% + 100               <br />set PDMM=%PDMM:~1,2%               <br />&#160;</code></p>
<p><b>Note </b>To calculate that the year was divisible by 4, a leap year, I could have replaced: </p>
<p><code>set /a PDDD=%PDYY% / 4              <br />set /a PDDD=%PDDD% * 4               <br />if %PDDD% EQU %PDYY% goto leap</code> </p>
<p>with: </p>
<p><code>set /a PDDD= %PDYY% ^%% 4              <br />if %PDDD% EQU 0 goto leap</code> <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I test / manipulate strings? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: If your batch script needs to determine if a string is a sub-set of a larger string, the easiest method is to use environment variable string substitution: </p>
<p><b>set work=%string:substring=%              <br />if not &quot;%work%&quot; EQU &quot;%string%&quot; @echo %string% contains substring.</b> </p>
<p>If the <b>substring</b> is an environment variable, <b>set work=%string:%substring%=%</b> or <b>set work=%%string:%substring%=%%</b> does <b>NOT</b> work. </p>
<p>You can use the <b>FOR</b> command to parse this expression, but using the <b>CALL</b> command is much easier: </p>
<p><b>call set work=%%string:%substring%=%%              <br />if not &quot;%work%&quot; EQU &quot;%string%&quot; @echo %string% contains %substring%.</b> </p>
<p>To determine if your path contains a specific folder, <b>call chkpath &quot;folder&quot;</b> </p>
<p>Example: call chkpath &quot;c:\program files\support tools&quot;, where <b>chkpath.bat</b> contains: </p>
<p><code>@echo off              <br />setlocal               <br />set $chkpath=N               <br />if {%1}=={} goto syntax               <br />set fold=%1               <br />:: Strip quotes               <br />set folder=%fold:&quot;=%               <br />call set work=%%path:%folder%=%%               <br />if &quot;%work%&quot; EQU &quot;%path%&quot; goto :end               <br />set $chkpath=Y               <br />goto :end               <br />:syntax               <br />@echo Syntax: ChkPath Folder               <br />:end               <br />endlocal&amp;set $chkpath=%$chkpath%               <br />&#160;</code></p>
<p><b>Note chkpath.bat</b> sets the <b>$chkpath</b> environment variable to <b>Y</b> if the string is found. </p>
<p>If you need to determine the position and length of the &quot;folder&quot; string in the path, <b>chkpath.bat</b> should contain: </p>
<p><code>@echo off              <br />setlocal               <br />set /a $pos=0               <br />set /a $len=0               <br />set $chkpath=N               <br />if {%1}=={} goto syntax               <br />set fold=%1               <br />:: Strip quotes               <br />set folder=%fold:&quot;=%               <br />call set work=%%path:%folder%=%%               <br />if &quot;%work%&quot; EQU &quot;%path%&quot; goto :end               <br />set $chkpath=Y               <br />set find=%folder%###               <br />:lenloop               <br />call set work=%%find:~%$len%,^3%%               <br />if &quot;%work%&quot; EQU &quot;###&quot; goto fndpos               <br />set /a $len=%$len% + 1               <br />goto lenloop               <br />:fndpos               <br />call set work=%%path:~%$pos%^,%$len%%%               <br />if /i &quot;%work%&quot; EQU &quot;%folder%&quot; goto :end               <br />set /a $pos=%$pos% + 1               <br />goto fndpos               <br />:syntax               <br />@echo Syntax: ChkPath Folder               <br />:end               <br />endlocal&amp;set $chkpath=%$chkpath%&amp;set /a $pos=%$pos%&amp;set /a $len=%$len%               <br />&#160;</code></p>
<p><b>Note $pos</b> starts at position 0. </p>
<h3>Sample Usage</h3>
<p>set look=c:\program files\support tools            <br />call chkpath &quot;%look%&quot;             <br />if &quot;%$chkpath%&quot; EQU &quot;Y&quot; @echo %look% is at position %$pos% for a length of %$len% <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I read a file and process the lines of text? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: To process the contents of a text file, you can parse it with the <b>FOR</b> command: </p>
<p><b>for /f &quot;Tokens=*&quot; %%a in (filenName.Extension) do set line=%%a&amp;call :parse</b> </p>
<p>         <dir>
<p>or</p>
<p>         </dir>
<p><b>for /f &quot;Tokens=*&quot; %%a in (&#8216;type &quot;filenName.Extension&quot;&#8217;) do set line=%%a&amp;call :parse</b> </p>
<p><b>Note </b>See <b>FOR /?</b> for additional options. </p>
<p><b>Example:</b> To display only those keys that have dword values, and their dword values, in a <b>c:\folder\registry.reg</b> file: </p>
<p><code>@echo off              <br />setlocal               <br />set key=               <br />for /f &quot;Tokens=*&quot; %%a in ('type d:\zipnew\zz.reg') do set line=%%a&amp;call :parse               <br />endlocal               <br />goto :EOF               <br />:parse               <br />::Strip command control codes               <br />set work=%line:&quot;=%               <br />set work=%work::=%               <br />set work=%work:(=%               <br />set work=%work:)=%               <br />set work=%work:^&amp;=%               <br />set work=%work:^|=%               <br />set work=%work:^&gt;=%               <br />set work=%work:^&lt;=%               <br />set work=%work:^%=%               <br />set work=%work:^!=%               <br />set work=%work:^;=%               <br />::Save the key               <br />if {%work:~0,1%}=={[} set key=%line%&amp;goto :EOF               <br />set dw=%work:dword=%               <br />if &quot;%dw%&quot; EQU &quot;%work%&quot; goto :EOF               <br />@echo %key% - %line%               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I launch a process at a different priority? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: When you type <b>start /?</b>, you receive: </p>
<p><code>Starts a separate window to run a specified program or command.              </p>
<p>START [&quot;title&quot;] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]               <br />[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]               <br />[/WAIT] [/B] [command/program]               <br />[parameters]               </p>
<p>&quot;title&quot; Title to display in window title bar.               <br />path Starting directory               <br />B Start application without creating a new window. The               <br />application has ^C handling ignored. Unless the application               <br />enables ^C processing, ^Break is the only way to interrupt               <br />the application               <br />I The new environment will be the original environment passed               <br />to the cmd.exe and not the current environment.               <br />MIN Start window minimized               <br />MAX Start window maximized               <br />SEPARATE Start 16-bit Windows program in separate memory space               <br />SHARED Start 16-bit Windows program in shared memory space               <br />LOW Start application in the IDLE priority class               <br />NORMAL Start application in the NORMAL priority class               <br />HIGH Start application in the HIGH priority class               <br />REALTIME Start application in the REALTIME priority class               <br />ABOVENORMAL Start application in the ABOVENORMAL priority class               <br />BELOWNORMAL Start application in the BELOWNORMAL priority class               <br />WAIT Start application and wait for it to terminate               <br />command/program               <br />If it is an internal cmd command or a batch file then               <br />the command processor is run with the /K switch to cmd.exe.               <br />This means that the window will remain after the command               <br />has been run.               </p>
<p>If it is not an internal cmd command or batch file then               <br />it is a program and will run as either a windowed application               <br />or a console application.               </p>
<p>parameters These are the parameters passed to the command/program               </p>
<p>If Command Extensions are enabled, external command invocation               <br />through the command line or the START command changes as follows:               </p>
<p>non-executable files may be invoked through their file association just               <br />by typing the name of the file as a command. (e.g. WORD.DOC would               <br />launch the application associated with the .DOC file extension).               <br />See the ASSOC and FTYPE commands for how to create these               <br />associations from within a command script.               </p>
<p>When executing an application that is a 32-bit GUI application, CMD.EXE               <br />does not wait for the application to terminate before returning to               <br />the command prompt. This new behavior does NOT occur if executing               <br />within a command script.               </p>
<p>When executing a command line whose first token is the string &quot;CMD &quot;               <br />without an extension or path qualifier, then &quot;CMD&quot; is replaced with               <br />the value of the COMSPEC variable. This prevents picking up CMD.EXE               <br />from the current directory.               </p>
<p>When executing a command line whose first token does NOT contain an               <br />extension, then CMD.EXE uses the value of the PATHEXT               <br />environment variable to determine which extensions to look for               <br />and in what order. The default value for the PATHEXT variable               <br />is:               </p>
<p>.COM;.EXE;.BAT;.CMD               </p>
<p>Notice the syntax is the same as the PATH variable, with               <br />semicolons separating the different elements.               </p>
<p>When searching for an executable, if there is no match on any extension,               <br />then looks to see if the name matches a directory name. If it does, the               <br />START command launches the Explorer on that path. If done from the               <br />command line, it is the equivalent to doing a CD /D to that path.               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I display the current directory in the Title bar of a batch files command Windows? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The <b>start</b> command can set the initial Title in a command Window. </p>
<p>To cause the batch file to display the current directory every time it changes, add the following commands after each current directory change: </p>
<p><code>for /f &quot;Tokens=*&quot; %%i in ('CD') do set CurDir=%%i              <br />title %CurDir%               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can a batch file alter the size of its&#8217; CMD Window? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: If you want to scroll the CMD window while a batch file is running, you can alter the Windows width (characters) and depth (screen buffer lines) by issuing a <b>mode</b> command in the batch file: </p>
<p><b>mode con[:] [cols=c] [lines=n]</b> </p>
<p>where: </p>
<p><code>             <br /><b>con[:]</b> indicates the change is to be made to the current command prompt window.               </p>
<p><b>cols=c</b> specifies the width, <b>c</b>, in characters.               </p>
<p><b>lines=n</b> specifies the number of lines, <b>n,</b> in the screen buffer.               <br />&#160;</code></p>
<p><b>Example:</b> mode con: cols=100 lines=999 <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I get a batch file to prompt for user input? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The <b>SET</b> command support the <b>/P</b> switch: </p>
<p><b>SET /P variable=[promptString]</b> </p>
<p>&quot;The /P switch allows you to set the value of a variable to a line of input            <br />entered by the user. Displays the specified promptString before reading             <br />the line of input. The promptString can be empty.&quot; </p>
<p><b>Example:</b> To prompt for folders to <b>DIR</b>: </p>
<p><code>@echo off              <br />setlocal               <br />:loop               <br />::undefine the %folder% environment variable               <br />set folder=               <br />set /p folder=Type the folder path and press Enter. When finished, press Enter.               <br />if {%folder%}=={} goto :end               <br />@echo.               <br />if not exist %folder% @echo %folder% does NOT exist.&amp;goto :loop               <br />dir %folder%               <br />@echo.               <br />goto loop               <br />:end               <br />endlocal               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I get a batch file to &#8216;sleep&#8217; for n seconds? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The Windows 2000 Resource Kits provide <b>sleep.exe</b> to allow a batch file to sleep for <i>n</i> seconds. </p>
<p>You can emulate this behavior by using the <b>PING</b> (<b>P</b><font size="1">acket</font> <b>I</b><font size="1">nter</font><b>N</b><font size="1">et</font> <b>G</b><font size="1">roper) command:</font> </p>
<p><b>ping -n <i>seconds</i>+<i>1</i> 127.0.0.1&gt;nul</b> </p>
<p>To sleep for 15 seconds, type: </p>
<p>ping -n 16 127.0.0.1&gt;nul <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I get a batch file to beep for attention? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: To cause a batch file to beep for attention, you need to send a BEL character. </p>
<p>To create a <b>Bell.bat</b> in your path: </p>
<ol>
<li>At a CMD prompt, switch (CD) to a folder in your path. </li>
<li>Type:
<p><code><b>edit bell.bat</b>                   <br /><b>@echo&lt;space&gt;&lt;CTRL+P&gt;&lt;CTRL+G&gt;&lt;ENTER&gt;</b>                   <br /><b>&lt;ALT+S&gt; (Saves bell.bat)</b>                   <br /><b>&lt;ALT+X&gt; (Exits edit)</b>                   <br />&#160;</code> </p>
</li>
</ol>
<p><b>Note </b>&lt;&gt; indicates that you type the key(s) within the &lt;&gt;. </p>
<p>When you need to beep for attention: </p>
<p><b>call bell</b> <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I pipe batch output, including commands and responses, to a log file? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The general syntax for piping batch output, including commands and responses, to a log file is: </p>
<p><b>Drive:\BatFolder\BatchName.bat&gt;Drive:\LogFolder\LogName.log 2&gt;&amp;1</b> <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What is delayed environment variable expansion? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>The default behavior of the CMD command processor is to evaluate an environment variable once per statement execution. </p>
<p>To demonstrate this behavior, assume that your c:\test folder has 3 files: </p>
<p>File1.txt            <br />File2.txt             <br />File3.txt </p>
<p>If you run a batch script containing: </p>
<p><code>@echo off              <br />cd /d c:\test               <br />@echo on               <br />set LIST=               <br />for %%i in (*) do set LIST=%LIST% %%i               <br />echo %LIST%               <br />&#160;</code></p>
<p>You would see the following: </p>
<p><code>C:\TEST\&gt;set LIST=              <br />C:\TEST\&gt;for %i in (*) do set LIST= %i               <br />C:\TEST\&gt;set LIST= File1.txt               <br />C:\TEST\&gt;set LIST= File2.txt               <br />C:\TEST\&gt;set LIST= File3.txt               <br />C:\TEST\&gt;echo File3.txt               <br />C:\TEST\&gt; File3.txt</code> </p>
<p>&#160;</p>
<p>You can see from this example that the LIST variable is expanded just once when the FOR statement is executed. Since LIST was empty, only the last file found is set into the variable. </p>
<p>Windows 2000 supports delayed environment variable expansion. You must enable delayed environment variable expansion for the CMD session by using the CMD /V:ON switch, or by issuing a <b>setlocal ENABLEDELAYEDEXPANSION</b> command. </p>
<p>With delayed environment variable expansion enabled, you can use the ! instead of the %, as follows: </p>
<p><code>@echo off              <br />cd /d c:\test               <br />@echo on               <br />set LIST=               <br />for %%i in (*) do set LIST=!LIST! %%i               <br />echo %LIST%               <br />&#160;</code></p>
<p>This yields the following output: </p>
<p><code>C:\TEST\&gt;set LIST=              <br />C:\TEST\&gt;for %i in (*) do set LIST=!LIST! %i               <br />C:\TEST\&gt;set LIST=!LIST! File1.txt               <br />C:\TEST\&gt;set LIST=!LIST! File2.txt               <br />C:\TEST\&gt;set LIST=!LIST! File3.txt               <br />C:\TEST\&gt;echo File1.txt File2.txt File3.txt               <br />C:\TEST\&gt; File1.txt File2.txt File3.txt</code> </p>
<p>&#160;</p>
<p>You can have delayed environment variable expansion enabled by default, if you use Regedt32 to navigate to either of the following keys: </p>
<p><code><b>HKEY_LOCAL_MACHINE \Software \Microsoft \Command Processor</b>               </p>
<p><b>HKEY_CURRENT_USER \Software \Microsoft \Command Processor</b>               <br />&#160;</code></p>
<p>On the <b>Edit</b> menu, <b>Add Value</b> name <b>DelayedExpansion</b>, as a <b>REG_DWORD</b> data type. A data value of <b>1</b> enables delayed environment variable expansion and a data value of <b>0</b> disables it. Invoking the <b>/V:ON</b> or <b>/V:OFF</b> switch on CMD.EXE and/or using the <b>setlocal ENABLEDELAYEDEXPANSION</b> command, overrides the registry setting for the CMD session. <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">What are the conditional processing symbols? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: From the <b>ntcmds.chm</b> file: </p>
<p><code>Conditional processing symbols give you control over the execution of commands.              <br />Processing Commands Conditionally You use conditional processing symbols to issue               <br />multiple commands from the same prompt and to act based on the results of a command.               <br />The ampersand (&amp;) separates multiple commands on one command line.               <br />The parentheses groups multiple commands.               <br />The semicolon or comma (; ,) separate command parameters.               <br />The caret (^) cancels a subsequent command symbol's special meaning so you can use a               <br />command symbol as text.               <br />The double ampersand (&amp;&amp;) causes the command following this symbol to run only if the               <br />command preceding the symbol is successful.               <br />The double pipe (||) causes the command following this symbol to run only if the command               <br />preceding the symbol fails.               <br />&#160;</code></p>
<p><b>Examples:</b> </p>
<p><b>dir filename.txt&gt;nul &amp;&amp; type filename.txt </b>is equivalent to if exist<b> filename.txt type filename.txt</b> </p>
<p><b>dir filename.txt&gt;nul || @echo.&gt;filename.txt </b>is equivalent to<b> if not exist filename.txt @echo.&gt;filename.txt</b> <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I send a pop-up message? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The syntax of the <b>net send</b> command is: </p>
<p><b>net send {name | * | /domain[:name] | /users} message</b> </p>
<p>To send a pop-up to all users in your domain, type: </p>
<p><b>net send /domain This is a message.</b> </p>
<p><b>Note</b> Windows NT-based client run the <b>Messenger</b> service by default. Other Windows clients must be running <b>Winpopup.exe</b> to receive the message. </p>
<p><b>net send jennifer hello</b> will send <b>hello</b> to <b>Jennifer</b>, if she is logged on. </p>
<p><b>net send /users hello</b> will send <b>hello</b> to <b>all users</b> that are connected to your computer. </p>
<p>To send a files contents to logged on members of one or more domain groups, use: </p>
<p><b>call sendfilegroup filename.txt group1 [group2 group3 ... groupn], </b>where <b>sendfilegroup.bat </b>contains: </p>
<p><code>@echo off              <br />setlocal ENABLEDELAYEDEXPANSION               <br />if {%2}=={} (echo usage: sndflegrp msgfile group-list) &amp; (goto :EOF)               <br />if not exist %1 (echo usage: sndflegrp msgfile group-list) &amp; (goto :EOF)               <br />set msg=               <br />for /f &quot;Tokens=*&quot; %%m in ('type %1') do set msg=!msg! %%m               <br />:LOOP               <br />if {%2}=={} endlocal&amp;goto :EOF               <br />for /f &quot;Skip=8 Tokens=*&quot; %%i in ('net group %2 /domain') do call :msg &quot;%%i&quot;               <br />shift /2               <br />goto :LOOP               <br />:msg               <br />If %1==&quot;The command completed successfully.&quot; goto :EOF               <br />set users=%1               <br />set user=%users:~1,20%##               <br />call :sndmsg&gt;nul 2&gt;&amp;1               <br />if &quot;%user%&quot;==&quot;&quot; goto end               <br />set user=%users:~26,20%##               <br />call :sndmsg&gt;nul 2&gt;&amp;1               <br />if &quot;%user%&quot;==&quot;&quot; goto end               <br />set user=%users:~51,20%##               <br />call :sndmsg&gt;nul 2&gt;&amp;1               <br />goto :EOF               <br />:sndmsg               <br />set user=%user: =%               <br />set user=%user: ##=##%               <br />set user=%user:##=%               <br />set user=%user:&quot;=%               <br />if &quot;%user%&quot;==&quot;&quot; goto :EOF               <br />set comp=%user%               <br />set comp=%comp:$=%               <br />if &quot;%comp%&quot;==&quot;%user%&quot; net send &quot;%user%&quot; %msg%               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I execute a command in every sub-folder? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: The <b>FOR /R</b> command is meant to traverse sub-folders. </p>
<p>The general syntax is: </p>
<p><b>FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]</b> </p>
<p><b>Walks the directory tree rooted at [drive:]path, executing the FOR              <br />statement in each directory of the tree. If no directory               <br />specification is specified after /R then the current directory is               <br />assumed. If set is just a single period (.) character then it               <br />will just enumerate the directory tree.</b> </p>
<p><b>Examples:</b> </p>
<p>To delete every *.<b>log</b> file in all the folders of your profile, type: </p>
<p>for /r &quot;%userprofile%&quot; %i in (*.log) do del /q &quot;%i&quot; </p>
<p><b>Note</b> If used in a batch file, the <b>%variable%</b> must be <b>%%variable%%.</b> </p>
<p>To list all the sub-folders of your profile, type: </p>
<p>for /r &quot;%userprofile%&quot; %i in (.) do @echo %i </p>
<p>To list every sub-folder of the current directory, type: </p>
<p>for /r %i in (.) do @echo %i <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How do I remove all files and sub-directories from a folder, without removing the folder? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: Typing <b>RD</b> /<b>S</b> /<b>Q</b> &lt;<b>Drive:</b>&gt;\<b>FolderName</b> will delete &lt;Drive:&gt;\FolderName, all it&#8217;s files, and sub-folders. </p>
<p>If you do <b>NOT</b> wish to remove the target folder, create <b>DELTREE.BAT</b> in your path: </p>
<p>@echo off            <br />pushd %1             <br />del /q *.*             <br />for /f &quot;Tokens=*&quot; %%i in (&#8216;dir /B&#8217;) do rd /s /q &quot;%%i&quot;             <br />popd </p>
<p>To delete all the files and sub-directories in <b>&lt;Drive:&gt;\My Test Folder, </b>type: </p>
<p><b>DELTREE &quot;&lt;Drive:&gt;\My Test Folder&quot;</b> <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I send e-mail from a batch script? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: If you wish to send an e-mail message from the command line or from a batch file, you can use <a href="http://www.interlog.com/~tcharron/blat.html">BLAT freeware</a>. </p>
<p>After installing <b>BLAT</b> by typing: </p>
<p><b>blat -install mail.jsiinc.com Jerry@jsiinc.com 3,</b><font size="1"> </font>I received: </p>
<p><b>Failed to open registry key for Blat profile , using default.              <br />SMTP server set to mail.jsiinc.com, on port 25 with user Jerry@jsiinc.com, retry 3 time(s)</b> </p>
<p>When I typed: </p>
<p><b>blat c:\temp\blatread.txt -to jerry@jsiinc.com -s &quot;This is a BLAT test&quot;</b>, the CMD window displayed: </p>
<p><code><b>Sending c:\temp\blatread.txt to jerry@jsiinc.com</b>               <br /><b>Subject:This is a BLAT test</b>               <br /><b>Login name is Jerry@jsiinc.com</b>               </p>
<p><b>Try number 1 of 3.</b>               <br />&#160;</code></p>
<p><b>AND</b> I received the e-mail, containing the contents of c:\temp\blatread.txt. <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">5527 [cchev] How can I retrieve basic user data? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: I have scripted <b>GetUserInfo.bat</b> to retrieve basic user data. The syntax is: </p>
<p><b>call getuserinfo UserName</b> </p>
<p>where <b>UserName</b> must be quoted if it contains any space characters. </p>
<p>To verify that the <b>UserName</b> was found, use a statement like: </p>
<p><b>if not defined $line1 goto NotFound</b> </p>
<p>After verifying that the <b>UserName</b> was found, you can access the basic user data by using the environment variables from the following table: </p>
<div class="tablediv">
<table class="dtTABLE" border="1" cellspacing="0">
<tbody>
<tr>
<th width="23%" align="left">Environment                    <br />Variables                     <br />&#160;</th>
<th width="42%" align="left">Description                    <br />&#160;</th>
<th width="35%" align="left">Sample Data                    <br />&#160;</th>
</tr>
<tr>
<td valign="top" width="23%"><b>$line1</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">User name                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Jerry                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line2</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Full Name                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Jerold Schulman                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line3</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Comment                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Sample Comment                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line4</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">User&#8217;s comment                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line5</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Country Code                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">000 (System Default)                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line6</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Account active                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Yes                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line7</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Account expires                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Never                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line8</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Password last set                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">07/12/2002 20:27                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line9</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Password expires                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">07/12/2002 20:27                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line10</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Password changeable                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">07/12/2002 20:27                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line11</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Password required                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Yes                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line12</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">User may change password                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">Yes                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line13</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Workstations allowed                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">All                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line14</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Logon script                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">logon.bat                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line15</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">User profile                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">profile path                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line16</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Home directory                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">home folder path                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
<tr>
<td valign="top" width="23%"><b>$line17</b>                     <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="42%">Last logon                    <br />&#160;
<p>&#160;</p>
</td>
<td valign="top" width="35%">07/15/2002 07:05                    <br />&#160;
<p>&#160;</p>
</td>
</tr>
</tbody>
</table></div>
<p><b>GetUserInfo.bat</b> contains: </p>
<p><code>@echo off              <br />if {%1}=={} goto syntax               <br />set /a cnt=0               <br />::<b>NOTE:</b> If you don't have a domain, change the following statemnt to: <b>for /f &quot;Tokens=*&quot; %%i in ('net user %1') do set line=%%i&amp;call :parse</b>               <br />for /f &quot;Skip=1 Tokens=*&quot; %%i in ('net user %1 /domain') do set line=%%i&amp;call :parse               <br />if %cnt% EQU 0 set $line1=               <br />set cnt=               <br />set line=               <br />goto :EOF               <br />:syntax               <br />endlocal               <br />@echo syntax: Call GetUserInfo &quot;UserName&quot;               <br />goto :EOF               <br />:parse               <br />set /a cnt=%cnt% + 1               <br />if /i &quot;%line%&quot;==&quot;The command completed successfully.&quot; goto :EOF               <br />if %cnt% GTR 17 goto :EOF               <br />set $line%cnt%=%line:~29,256%               <br />&#160;</code></p>
<h3>Sample Usage</h3>
<p>To implement a user locator for a single domain controller domain, create a <b>Locator$</b> share on your domain controller granting <b>Domain Users</b> Read and Write permissions, and <b>Creator Owner</b> delete permission. Add the following code to your logon script: </p>
<p><code>             <br />call getuserinfo &quot;%username%&quot;               <br />if defined $line1 del /q &quot;%LOGONSERVER%\Locator$\%userName%.*&quot;               <br />if defined $line1 @echo %$line2%&gt;&quot;%LOGONSERVER%\Locator$\%userName%.%ComputerName%&quot;               <br />&#160;</code></p>
<p>To locate a user, type: </p>
<p>dir &quot;%LOGONSERVER%\Locator$\UserName.*&quot; <!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I count the number of lines in a file, and/or display the last n lines? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: I have scripted <b>Tail.bat</b> to perform both functions. </p>
<p>The syntax is: </p>
<p><b>tail FileName [NumberOfLinesToDisplay]</b> </p>
<p>If<font size="1"> </font><b>NumberOfLinesToDisplay</b><font size="1"> </font>is 0, you can set the file line count by using: </p>
<p><b>for /f %%i in (&#8216;tail FileName 0&#8242;) do set lines=%%i</b> </p>
<p>If <b>NumberOfLinesToDisplay</b> is omitted, 10 lines will be displayed. </p>
<p>If <b>NumberOfLinesToDisplay</b> is greater than the lines in the file, all lines in the file will be displayed. </p>
<p><b>Tail.bat</b> contains: </p>
<p><code>@echo off              <br />if {%1}=={} @echo FileName parameter requied.&amp;goto :EOF               <br />if not exist %1 @echo %1 does NOT exist.&amp;goto :EOF               <br />setlocal               <br />set file=%1               <br />set /a number=10               <br />if not {%2}=={} set /a number=%2               <br />for /f %%i in ('find /v /c &quot;&quot; ^&lt; %file%') do set /a lines=%%i               <br />@echo %lines% lines in file %file%.               <br />if %number% GEQ %lines% set /a start=0&amp;goto console               <br />set /a start=%lines% - %number%               <br />:console               <br />more /e +%start% %file%               <br />endlocal               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">How can I create a file containing all the user names in my domain? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: I have scripted <b>AllUsers.bat</b> to retrieve the list of all user names in the client&#8217;s domain. The syntax is: </p>
<p><b>call AllUsers &quot;FileName&quot;</b> </p>
<p>where <b>FileName</b> is the full path to the file that will contain the user names. </p>
<p><b>AllUsers.bat</b> contains: </p>
<p><code>@echo off              <br />if {%1}=={} @echo Syntax: AllUsers &quot;FileName&quot;&amp;goto :EOF               <br />setlocal               <br />if exist %1 del /q %1               <br />set filename=%1               <br />for /f &quot;Skip=6 Tokens=*&quot; %%i in ('net user /domain') do set line=%%i&amp;call :parse               <br />endlocal               <br />goto :EOF               <br />:parse               <br />set name=%line:~0,25%               <br />If /i &quot;%name%&quot; EQU &quot;The command completed suc&quot; goto :EOF               <br />call :strip               <br />set name=%line:~25,25%               <br />if not &quot;%name%&quot; EQU &quot;&quot; call :strip               <br />set name=%line:~50,25%               <br />if not &quot;%name%&quot; EQU &quot;&quot; call :strip               <br />goto :EOF               <br />:strip               <br />set short=%name%#               <br />set short=%short: =%               <br />set short=%short: #=#%               <br />set short=%short:#=%               <br />@echo %short%&gt;&gt;%filename%               <br />&#160;</code></p>
<p><b>Sample Usage</b> </p>
<p>To create of report of all user names whose password has expired, or will expire today, <b>Expired.bat</b> contains: </p>
<p><code>@echo off              <br />if {%1}=={} @echo syntax: Expired &quot;ReportFile&quot;&amp;goto :EOF               <br />setlocal               <br />set filename=%1               <br />if exist %filename% del /q %filename%               <br />::Format Today as YYYYMMDD where %date% contains DAY MM/DD/YYYY               <br />set today=%date:~10,4%%date:~4,2%%date:~7,2%               <br />call allusers &quot;%TEMP%\AllUsers.txt&quot;               <br />for /f &quot;Tokens=*&quot; %%i in ('type &quot;%TEMP%\AllUsers.txt&quot;') do set user=%%i&amp;call :report               <br />if exist %filename% del /q %filename%               <br />endlocal               <br />goto :EOF               <br />:report               <br />call GetUserInfo &quot;%user%&quot;               <br />if not defined $line1 goto :EOF               <br />if /i &quot;%$line6%&quot; EQU &quot;No&quot; goto :EOF               <br />if /i &quot;%$line9%&quot; EQU &quot;Never&quot; goto :EOF               <br />::Set Password Expires to YYYYMMDD               <br />set passexp=%$line9:~6,4%%$line9:~0,2%%$line9:~3,2%               <br />If &quot;%passexp%&quot; GTR &quot;%today%&quot; goto :EOF               <br />::Set ruser to 26 characters               <br />set work=%user% #               <br />set ruser=%work:~0,26%               <br />::set Full Name to 40 characters               <br />set work=%$line2% #               <br />set fullname=%work:~0,40%               <br />@echo %ruser%%fullname%%passexp%&gt;&gt;%filename%               <br /></code><!--begin bookmark heading--></p>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><font class="head3" size="2" face="arial, helvetica"><b class="bold">&#8216;&lt;Command&gt;&#8217; is not recognized as an internal or external command, operable program or batch file? </b></font></td>
<td valign="bottom" align="right"><a href="#top" target="_self"></a></td>
</tr>
<tr>
<td bgcolor="#ffcc00" colspan="2"><img border="0" src="../images/spacer.gif" width="1" height="1" /></td>
</tr>
</tbody>
</table>
<p><img border="0" src="../images/spacer.gif" width="1" height="12" />             <br /><!--end bookmark heading--></p>
<p>Answer: If you receive the subject error message, the most likely cause is that the <b>%SystemRoot%\System32</b> folder is no longer in your path. Most systems should have a PATH variable that begins with entries similar to: </p>
<p>PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\WBEM; </p>
<p>Another possible reason for this error is that some application install changed the Path Value Name, in the registry, from a <b>REG_EXPAND_SZ</b> data type to a <b>REG_SZ</b> data type. </p>
<p>If this is your problem: </p>
<ol>
<li>Use Regedt32.exe to navigate to:
<p><b>HKEY_LOCAL_MACHINE \System \CurrentControlSet \Control \Session Manager\Environment</b> </p>
</li>
<li>If the <b>Path</b> Value Name is a type <b>REG_SZ</b>, double-click it and paste the data value into Notepad. </li>
<li>Delete the <b>Path </b>Value Name. </li>
<li>On the <b>Edit</b> menu, <b>Add Value</b> name <b>Path</b>, as a <b>REG_EXPAND_SZ</b> data type. </li>
<li>In the <b>String Editor</b>, paste the data value from Notepad. </li>
<li>You may have to restart your computer. </li>
</ol>
</td>
</tr>
</tbody>
</table>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=FAQ+%E2%80%93+Windows+Command+Processor+cmd.exe+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D715" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=FAQ+%E2%80%93+Windows+Command+Processor+cmd.exe+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D715" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2009/10/29/faq-windows-command-processor-cmd-exe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

