Hopefully "ScriptingTipsAndTricks" helps you with your batch file or vbscript scripting :-)
[Bottom][Contents][Prev]: TEE.EXE (input goes to stdout as well as a file)[Next]: 8.3 Filename from Long Name - gets legacy 8.3 formatted filename
\->Batch Files

Batch Files

Batch files are the simplest scripting (automation) mechanism provided by Windows. At its simplest it could be as small as a single command you need to re-use and saves you typing it every time, for example to get the latest version of a document off a file share you might type the following:

 copy "\\SomeServer\SomeShare\SomeFile.doc" "c:\Documents"

If you put that command into a file called "gd.cmd" then all you would need to do is type "gd" to copy the file!

You could even add a shortcut for this batch file into the "Startup" folder or schedule that command with Window's task scheduler and have it happen automatically.

Batch files can contain many lines of windows commands, invoke other useful programs you have installed or make decisions and alter flow.

The following example shows how could create a backup of your EverNote notes to backup it up to your computer and to the cloud:

 "C:\Program Files (x86)\Evernote\Evernote\ENScript.exe" exportNotes /q any: /f "C:\Dropbox\$Backups$\EVERNOTE BACKUP.enex"

There is a very good free PDF called "Batch File Programming (by S Premkumar)" which I recommend you have a look at.

Do not forget to look for useful programs even other scripting languages (such as rexx with its singe EXE no installation runtime) as anything that produces reasonable output to stdout or stderr can be used in batch file.

There are many interesting web sites where you can get more information (a good google should find them), there are quite a few good tips (and subroutines) at the "Batch Function Library for Windows NT4/2000/XP/2003" site, others are:

Example code & Fragments

Please see these fragments and examples:

Useful Tools & Links

Some sites with very useful information and tool links:


Please note that that I am not trying to show how great I am by producing batch files 9,000 characters long on one line that no one will understand or be able to debug when they go wrong. I am going out of my way to comment the code and make it verbose so beginners and advanced users will both benefit. I don't claim to be an expert that knows everything, if I'm wrong or make a mistake then please contact me and let me know :-)


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: TEE.EXE (input goes to stdout as well as a file)[Next]: 8.3 Filename from Long Name - gets legacy 8.3 formatted filename


ScriptingTipsAndTricks© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday September 07 2014 at 12:50pm
Visit ScriptingTipsAndTricks's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.