Instructables
Picture of Batch File Guide
Hi! Welcome to my Batch File Guide, I am relatively new to the batch language.  This is not an extremely detailed guide, because I believe that it is good to learn about this much of Batch and then start learning something like Python.  Also, if you have any suggestions or see something wrong with my guide, then please contact me, I like feedback. Remember, if you like my Instructable, please comment, favorite, and or SUBSCRIBE! Thank you.
 
Remove these adsRemove these ads by Signing Up

Step 1: Saving Your Batch File

After you write your batch program in your text editor (I use Notepad), you have to save the program as a .bat file. So you save it as your_file_name.bat, you must have the .bat ending every time or it will save as a .txt file instead of a .bat file.

Step 2: Printing "Hello, world!" Onto the Screen

Picture of Printing
cmd_hello_world.JPG
Well, your long awaited first batch file shall come at last. In it, you will print "Hello, world!" onto the screen. The function to print text onto the screen in batch is echo. Another thing to know is, in most batch files you make, the first line of code is @echo off, this makes it so the echo is hidden and it only shows the text you want to be shown. Now, put that into your code and then put echo Hello, world! on the next line. Now, if you save it as hello_world.bat and double-click on the batch file, it will open a CMD window and close it really fast. To keep it open and to let the user see the text you must use the pause function, so, on the next line type pause. Now finally, you are done, save it and double-click on the batch file icon. It should open a CMD window, print "Hello, world!" in the window, and say "Press any key to continue . . . ", after you press any key the window will close. Congratulations, you just made your first batch file!
amei44 months ago

launcher

@echo off

title LAUNCHER PRO

echo Hello %username%

pause

:top

cls

echo Hello %username%

echo Would you like to start

echo 1. Chrome (install)

echo 2. Internet Explorer

echo 3. Download Chrome

echo 4. Firefox (install)

echo 5. Download Firefox

echo 6. Opera (install)

echo 7. Install Opera

echo 8. Exit

set /p in=

if %in%==1 start chrome.exe

if %in%==2 start iexplore.exe

if %in%==3 start iexplore.exe https://www.google.com/intl/en/chrome/browser/

if %in%==4 start C:\Program Files\Mozilla Firefox\firefox.exe

if %in%==5 start iexplore.exe http://www.mozilla.org/en-US/firefox/new/

if %in%==6 start C:\Program Files\Opera.exe

if %in%==7 start iexplore.exe www.opera.com

if %in%==8 exit

) else (

goto loop

)

:loop

cls

echo %in% is not acceptible

echo Please write something acceptible

echo 1 2 3 4 5 6 7 8 is acceptible

pause

goto top

electronicz (author)  amei43 months ago

Cool, I made something like this in the past : )

-WorldBuilder

mjlush6 months ago
I'm really sorry to be negative about this .. but to be really really honest I would never advise anyone to put much effort into learning 'batch' programming. For one simple reason that a) its not portable (this instructable will work in MS windows and nowhere else) and more importantly b) its kind of a dead end (you start to push the limits quite quickly). I'd suggest that learning a scripting language like Python or Perl, you can do everything you can do in batch and its a gateway to much much more. The only time batch is worthwhile is when your not in a position to install anything better or your writing a smarter launcher/installer.
electronicz (author)  mjlush6 months ago

Hi, thanks for the feedback, and you aren't being negative at all. I whole heartedly agree with you. I recommend people to look a little at Batch and then learn something like Python (that is what I have been learning). I think someone shouldn't get farther than as far as this Instructable goes, because it is just meant for moving files, deleting files, and doing different tasks on your computer. You can make small programs and little games with Batch, but something like Python is way better suited for the job. Thanks for the feedback and I agree with you.