Batch files to automate tasks in Windows environment - tutorial

A Batch file is any file with an extension .bat . The batch file is special in the sense that whatever you enter in a batch file, will be run as Commands in Command Prompt one line at a time. The commands will be shown in the prompt as they are run.

Creating and Editing :

Creating and Editing Batch Files in WindowsCreate a batch file named batch.bat in your C:\WINDOWS folder. (take note pad and save the file as Save As batch.bat ). type something like shutdown /? inside the file after opening it in notepad or any other text editor and save the file. Go to Command Prompt START >> All Programs >> Accessories >> Command Prompt and type “batch”. A screen similar to the one shown below will appear. The shutdown /? command will show you a simple help on shutdown command’s options and usage. This is a simple example for using the batch file for automating tasks.

Create and Edit batch file

Working :

When you type “batch” in the command prompt Windows looks for executable files named batch first (.COM and then .EXE) then if both of them are not found Windows searches for a file with name batch and extension bat. So now Windows will have located our batch file. Then every line in the batch file are treated as commands. So we have shutdown /? on the first line. This is executed and the output is shown. The locations where Windows looks for commands are set in the PATH Environment Variable

To prevent showing each command on the command prompt before it is run, just add @echo=OFF to the first line of the batch file.

To create a Batch file Right Click and select NEW»Text Document. Rename it with FILENAME.bat (you must have disabled Hide extensions for known file types in Folder Options ). Now drag it to Notepad and type in the command you want to run, Save it (CTRL+S) and close. Or you can open notepad type the commands and then take File>>Save As and in the name filed give FILENAME.BAT and in the File Type give All Types.

At first you may seem this as non-useful but there are many parameters in command prompt including if, for etc.. which will make this a whole lot useful. I will cover automating the tasks in next part of this tutorial.

Buy me a cup of hot coffee - help me keep posting all through the night

If you are new here you may want to subscribe to this blogs full feed RSSSubscribe to full feed RSS of this blog
so that you will get the updates automatically to your feed reader.

Tags: ,

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post



My Google  Netvibes  My Yahoo!  Windows Live  Bloglines  Newsgator