<?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>devtrends.com &#187; Batch Files</title>
	<atom:link href="http://www.devtrends.com/index.php/category/software-development/batch-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devtrends.com</link>
	<description>developing trends in information technology</description>
	<lastBuildDate>Tue, 06 Sep 2011 19:27:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Deploying Applications with the Possibility of a Slow Connection (Robocopy)</title>
		<link>http://www.devtrends.com/index.php/deploying-applications-with-the-possibility-of-a-slow-connection/</link>
		<comments>http://www.devtrends.com/index.php/deploying-applications-with-the-possibility-of-a-slow-connection/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 19:43:49 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Batch Files]]></category>
		<category><![CDATA[Microsoft O/S]]></category>
		<category><![CDATA[zFeatured]]></category>
		<category><![CDATA[robocopy]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.devtrends.com/?p=523</guid>
		<description><![CDATA[Regardless of which software deployment suite you use in your organization, there is no way to avoid transferring the majority of the installation files to the local machine, whether that...]]></description>
			<content:encoded><![CDATA[<p>Regardless of which software deployment suite you use in your organization, there is no way to avoid transferring the majority of the installation files to the local machine, whether that is a file copy or a load into memory / temporary location. For small application deployments, running them directly from a share location on a server isn’t necessarily a bad idea, even if the user is connected remotely. However, on the other side of the spectrum, installing Microsoft Office from a server share, while connected remotely, is a bad idea.</p>
<p>So what is the solution? How about staging the files on the local hard drive prior to starting the installation? Your first thought might be a batch file or command script that uses xcopy – at least that was my first thought. However, xcopy assumes that your connection will not drop and that it is fairly fast. What happens when the user is remote and while copying the files the user disconnects from the Internet and Virtual Private Network (VPN)? The file copy process has to start over…</p>
<p>With robocopy, a Microsoft product, you can configure it to copy with resume capabilities. In addition, if you show the installation process to your users (different discussion), each file in the copy process displays its current transferred status (0-100%).</p>
<p><a href="http://www.devtrends.com/wp-content/uploads/2010/02/robocopy1.jpg"><img class="alignnone size-medium wp-image-524" title="robocopy1" src="http://www.devtrends.com/wp-content/uploads/2010/02/robocopy1-300x151.jpg" alt="" width="300" height="151" /></a></p>
<p><strong>Getting RoboCopy</strong></p>
<p>Robocopy is available for free from Microsoft as part of the Microsoft Windows Server 2003 <a href="http://go.microsoft.com/fwlink/?LinkId=72969" target="_blank">Resource Kit Tools</a>. The command line options are somewhat daunting, something you’d expect to see from the “grep &#8211;help” command in Linux. In this article we only use a small amount of the power that is Robocopy. For those that dislike command line tools, but still need the functionality of Robocopy, have a look at the GUI tools available for Robocopy.</p>
<ul>
<li><a href="http://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx" target="_blank">Utility Spotlight Robocopy GUI</a></li>
<li><a href="http://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx" target="_blank">Utility Spotlight RichCopy</a></li>
</ul>
<p><strong>Simple Deployment Script (Adobe Reader)</strong></p>
<p>Below is an example for deploying Adobe Reader to clients utilizing the Robocopy tool.</p>
<pre style="padding-left: 30px;">@ECHO OFF</pre>
<pre style="padding-left: 30px;">rem Create log folder, just in case it does not exist
md C:\installer
md C:\installer\logs
md C:\installer\AdobeReader9.3.0</pre>
<pre style="padding-left: 30px;">rem Bring down the files to the local drive
"\\installer\dist$\robocopy.exe" "\\installer\dist$\AdobeReader" "c:\installer\AdobeReader9.3.0" *.* /E /Z</pre>
<pre style="padding-left: 30px;">rem begin installation
msiexec.exe /i c:\installer\AdobeReader9.3.0\AcroRead.msi TRANSFORMS=c:\installer\AdobeReader9.3.0\AcroRead.mst /qn /l*v C:\installer\logs\AdobeReader9.3.0.log</pre>
<p><strong>Robocopy Command Line Options</strong></p>
<pre>C:\&gt;robocopy /?

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Fri Feb 05 10:30:35 2010

              Usage :: ROBOCOPY source destination [file [file]...] [options]

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               file :: File(s) to copy  (names/wildcards: default is "*.*").

::
:: Copy options :
::
                 /S :: copy Subdirectories, but not empty ones.
                 /E :: copy subdirectories, including Empty ones.
             /LEV:n :: only copy the top n LEVels of the source directory tree.

                 /Z :: copy files in restartable mode.
                 /B :: copy files in Backup mode.
                /ZB :: use restartable mode; if access denied use Backup mode.

  /COPY:copyflag[s] :: what to COPY (default is /COPY:DAT).
                       (copyflags : D=Data, A=Attributes, T=Timestamps).
                       (S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

               /SEC :: copy files with SECurity (equivalent to /COPY:DATS).
           /COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
            /NOCOPY :: COPY NO file info (useful with /PURGE).

             /PURGE :: delete dest files/dirs that no longer exist in source.
               /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).

               /MOV :: MOVe files (delete from source after copying).
              /MOVE :: MOVE files AND dirs (delete from source after copying).

       /A+:[RASHNT] :: add the given Attributes to copied files.
       /A-:[RASHNT] :: remove the given Attributes from copied files.

            /CREATE :: CREATE directory tree and zero-length files only.
               /FAT :: create destination files using 8.3 FAT file names only.
               /FFT :: assume FAT File Times (2-second granularity).
               /256 :: turn off very long path (&gt; 256 characters) support.

             /MON:n :: MONitor source; run again when more than n changes seen.
             /MOT:m :: MOnitor source; run again in m minutes Time, if changed.

      /RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
                /PF :: check run hours on a Per File (not per pass) basis.

             /IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.

::
:: File Selection Options :
::
                 /A :: copy only files with the Archive attribute set.
                 /M :: copy only files with the Archive attribute and reset it.
    /IA:[RASHCNETO] :: Include only files with any of the given Attributes set.
    /XA:[RASHCNETO] :: eXclude files with any of the given Attributes set.

 /XF file [file]... :: eXclude Files matching given names/paths/wildcards.
 /XD dirs [dirs]... :: eXclude Directories matching given names/paths.

                /XC :: eXclude Changed files.
                /XN :: eXclude Newer files.
                /XO :: eXclude Older files.
                /XX :: eXclude eXtra files and directories.
                /XL :: eXclude Lonely files and directories.
                /IS :: Include Same files.
                /IT :: Include Tweaked files.

             /MAX:n :: MAXimum file size - exclude files bigger than n bytes.
             /MIN:n :: MINimum file size - exclude files smaller than n bytes.

          /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
          /MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
          /MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
          /MINLAD:n :: MINimum Last Access Date - exclude files used since n.
                       (If n &lt; 1900 then n = n days, else n = YYYYMMDD date).

                /XJ :: eXclude Junction points. (normally included by default).

::
:: Retry Options :
::
               /R:n :: number of Retries on failed copies: default 1 million.
               /W:n :: Wait time between retries: default is 30 seconds.

               /REG :: Save /R:n and /W:n in the Registry as default settings.

               /TBD :: wait for sharenames To Be Defined (retry error 67).

::
:: Logging Options :
::
                 /L :: List only - don't copy, timestamp or delete any files.
                 /X :: report all eXtra files, not just those selected.
                 /V :: produce Verbose output, showing skipped files.
                /TS :: include source file Time Stamps in the output.
                /FP :: include Full Pathname of files in the output.

                /NS :: No Size - don't log file sizes.
                /NC :: No Class - don't log file classes.
               /NFL :: No File List - don't log file names.
               /NDL :: No Directory List - don't log directory names.

                /NP :: No Progress - don't display % copied.
               /ETA :: show Estimated Time of Arrival of copied files.

          /LOG:file :: output status to LOG file (overwrite existing log).
         /LOG+:file :: output status to LOG file (append to existing log).

               /TEE :: output to console window, as well as the log file.

               /NJH :: No Job Header.
               /NJS :: No Job Summary.

::
:: Job Options :
::
       /JOB:jobname :: take parameters from the named JOB file.
      /SAVE:jobname :: SAVE parameters to the named job file
              /QUIT :: QUIT after processing command line (to view parameters).

              /NOSD :: NO Source Directory is specified.
              /NODD :: NO Destination Directory is specified.
                /IF :: Include the following Files.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.devtrends.com/index.php/deploying-applications-with-the-possibility-of-a-slow-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VCB Backup Script, vcbMounter</title>
		<link>http://www.devtrends.com/index.php/vcb-backup-script-vcbmounter/</link>
		<comments>http://www.devtrends.com/index.php/vcb-backup-script-vcbmounter/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 06:13:22 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Batch Files]]></category>
		<category><![CDATA[VCB]]></category>
		<category><![CDATA[zFeatured]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[vcbMounter]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://www.devtrends.com/?p=474</guid>
		<description><![CDATA[Although the VMware Consolidated Backup (VCB) software receives considerable flack for lacking features or functionality, the fact that it provides you with access to the raw VMDK files is enough...]]></description>
			<content:encoded><![CDATA[<p>Although the VMware Consolidated Backup (VCB) software receives considerable flack for lacking features or functionality, the fact that it provides you with access to the raw VMDK files is enough to alleviate all the missing functionality. As a side note, with Windows VMs, you can also use the vcbMounter program to mount the VM at a file level &#8212; which eliminates the need for backup client software on the VMs.</p>
<p><strong>Full VMDK Backups</strong></p>
<p>The first thing I&#8217;d like to point out is that the vcbMounter does not &#8220;mount&#8221; the datastore of the VM as one might imagine. When using the vcbMounter program to access the VMDK files, vcbMounter only copies the files to your VCB server. For smaller VMs, 30GB or so, this really isn&#8217;t much of an issue; however, for the larger VMs, say 300GB, this could pose a problem.</p>
<p>At first, you may be frustrated as the vcbMounter program is a quirky program. Unless you are lucky or brilliant, give yourself some time to play with the command options.</p>
<p>For my purposes, I use the following vcbMounter statement:</p>
<pre style="padding-left: 30px;">vcbmounter -h [VC or HOST] -u [USERNAME] -p [PASSWORD] -M 1 -a name:[VM NAME] -r [LOCATION]\%1_vmdk</pre>
<p><strong>vmdkbkp.bat</strong></p>
<p>As expected, I am backing up many VMs; who would have an ESX(i) host with only one VM? (that is an entirely different subject I may address another day). Instead of scheduling the full vcbMounter command with each backup script or scheduled task, I created a batch file I use to extract the VMDK files. If you are interested in my script, <a href="http://www.devtrends.com/downloads/vmdkbkp.zip">download here</a>.</p>
<pre style="padding-left: 30px;">@ECHO OFF
rem ----------------------------------------------------------------
rem Batch file to create a "mount" dump of a VM, as specified in %1.
rem Created, 11/23/2009, Aaron Gilbert, www.devtrends.com
rem
rem Usage: vmdkbkp.bat [server name]
rem  e.g.: vmdkbkp MYSERVERNAMEINESX
rem
rem ----------------------------------------------------------------

rem check to make sure the user supplied an argument
if "%1"=="" goto error

rem format date in yyyy-mm-dd to apply to a directory, use is %today%
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set today=%%c-%%a-%%b)

rem update the path statement so we can use vcbmounter
PATH=%PATH%;"C:\Program Files\VMware\VMware Consolidated Backup Framework\"

rem begin vcbmounter to copy the VMDK files down in file size (no 2GB split)
vcbmounter -h [VC or HOST] -u [USERNAME] -p [PASSWORD] -M 1 -a name:%1 -r [LOCATION]\%1_vmdk_%today%

rem lets finish up without error!
goto done

rem fail...
:error
echo.
echo Please provide one argument in the form of a VM server name, such as MYSERVERNAMEINESX
echo.

rem clean complete
:done</pre>
<p>The batch file requires only one argument, the name of the VM server you wish to backup. I use the batch file in conjunction with a non-traditional vcbMounter &#8220;mounting&#8221; approach. I &#8220;mount&#8221; with the intent of keeping that &#8220;mount&#8221; for an extended period of time. In addition to the vmdkbkp.bat file, I use another batch file to clean out the backup directory of all &#8220;mounted&#8221; directories older than a specific date. This allows me to keep the VMDK files on my backup-to-disk server for multiple weeks, while rotating out the older files.</p>
<pre style="padding-left: 30px;">@ECHO OFF
rem -------------------------------------------------------------
rem Batch file to remove all directories that are older than %1.
rem Created, 11/24/2009, Aaron Gilbert, www.devtrends.com
rem
rem Usage: clndir.bat [negative days]
rem  e.g.: clndir -3
rem
rem -------------------------------------------------------------

rem check to make sure the user supplied an argument
if "%1"=="" goto error

rem clean up the directory from all directories older than 3 days
forfiles.exe /p c:\backup\ /m *.* /d %1 /c "cmd /c if @isdir==TRUE rmdir /s /q @path"

rem lets finish up without error!
goto done

rem fail...
:error
echo.
echo Please provide one argument in the form of a negative number, such as -3
echo.

rem clean complete
:done</pre>
<p>Aaron Gilbert</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtrends.com/index.php/vcb-backup-script-vcbmounter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Echo Without Carriage Return or Line Feed (CR LF)?</title>
		<link>http://www.devtrends.com/index.php/echo-without-carriage-return-or-line-feed-cr-lf/</link>
		<comments>http://www.devtrends.com/index.php/echo-without-carriage-return-or-line-feed-cr-lf/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 04:46:48 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Batch Files]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[crlf]]></category>
		<category><![CDATA[echo]]></category>

		<guid isPermaLink="false">http://www.devtrends.com/?p=397</guid>
		<description><![CDATA[Recently, I wanted to make a terminal application automatically use the current signed-in Windows user name as the terminal session user name. When I first started on the task, I...]]></description>
			<content:encoded><![CDATA[<p>Recently, I wanted to make a terminal application automatically use the current signed-in Windows user name as the terminal session user name. When I first started on the task, I thought this will be easy; what acclaimed terminal program with heavily definable session settings is not capable of such? Well shoot &#8211; I was mistaken. However, I have never given up on the impossible in the past, and quite frankly this task was definitely not impossible in comparison to other tasks or projects…</p>
<p>As a quick overview to help you understand the problem, each session configuration is kept in individual files located in the \scripts\ folder within the application folder. The session files were not a standard format, such as an INI or XML, and appeared as though the application developer(s) used some proprietary data component for saving session configuration to the hard drive. While reviewing the session files with <a href="http://www.ultraedit.com/" target="_blank">UltraEdit</a>, I noticed that the data values were in standard text format amongst a fog of extended ASCII characters.</p>
<p>Ah ha! Concatenation is the solution…will it be batch file or .NET application?</p>
<p><a href="http://www.developingtrends.net/wp-content/uploads/2009/10/ilovedos.jpg"><img class="alignnone size-medium wp-image-400" title="ilovedos" src="http://www.devtrends.com/wp-content/uploads/2009/10/ilovedos-300x151.jpg" alt="ilovedos" width="300" height="151" /></a></p>
<p><strong>Gluing the Pieces Together</strong></p>
<p>Runner up, the batch file. I took the session configuration file and cut it right down the middle (where the user name value was), saving one half as session.p1 and the other half as session.p2. The next trick was to glue these files back together with the current Windows user name in between. I grew up using DOS so I thought that this would be easy; I could just echo %USERNAME% to a file, such as:</p>
<pre style="padding-left: 30px;">echo %USERNAME% &gt; session.nam</pre>
<p>Unfortunately, the echo command puts a CR/LF at the end of the file, even though %USERNAME% contains no such characters. Logic would state that since echo is typically used for screen output, it assumes that you want a line feed after your statement. Well, a line feed is going to break my batch file concatenation solution; I can’t have line feeds in a proprietary configuration file!</p>
<p><strong>Solution</strong></p>
<p>After much research, I pieced together a batch file line that echo’s a statement without line feeds! This is a golden nugget for anyone that is trying to solve this problem and it worked quite well in my batch file concatenation solution!</p>
<pre style="padding-left: 30px;">for %%a in (%USERNAME%) do (
echo/|set /p ="%%a"
) &gt; session.nam</pre>
<p>Obviously, you can replace %USERNAME% with any environment variable or text that you want – no quotes required.</p>
<p>Remember that where there is a will to do so, there is a way to accomplish any task.</p>
<p>Aaron Gilbert</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devtrends.com/index.php/echo-without-carriage-return-or-line-feed-cr-lf/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

