How to program .bat files (Windows Batch Files).
TROUBLESHOOTING: If your program immediately disappears, put the command pause at the end.
Works on Windows XP and up. Limited functionality is included in Windows 95 and 98.
First, you must open Notepad (Start –> Run –> notepad)
Then, open the file menu and click Save As.
Pull down the Save as Type menu and select All Files (*.*).
Finally, name your file, put .bat after it, and save it anywhere.
Now, to edit the program file you just created, right click on the batch file (.bat) and select Edit.
We’re back in Notepad and it’s time to create the program.
If you want to use echo in your program (display text on the screen) or even if you don’t, it’s a good idea to put the command @echo off at the top of your program. It enables you to use echo without the batch’s path file.
Then you should probably set the title (the top bar) of your program with the title command, and put your title after it, like so:
title This is my new program!
Now you can do whatever you want with your program, so let’s slow down and see how the commands work.
echo = displays something on the screen, like this:
echo Hello world.
To skip a line, use echo. .
P.S. Skipping lines in notepad doesn’t make any difference in the actual program.
cls = Clears the screen
pause = displays Press any key to continue…
So our program so far is:
title This is my first batch program!
echo Hello world.
echo I just cleared the screen!
To get someone’s input, use the command set /p (variable name)=(question). For example, you could do the following:
title Register yourself!
echo Please fill out the following form:
set /p name=What is your name?
set /p age=How old are you?
set /p reason=Why are you registering here?
echo Ok. I got it.
echo %name% is %age% years old and registered because %reason%.
Switches coming soon!