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.

13 thoughts on “Batch files to automate tasks in Windows environment – tutorial”

  1. monochrome mostel brinton cripple leightsinn palluch compartmentalize falling hotzenplotz

  2. Hi i like the great information that you posted here, but you should check is there something wrong with the theme? because i can not click other links other than posted this comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>