Introduction: EASY BATCH FILE
This is how to make a simple batch file.
Step 1:
OPEN NOTEPAD.
Step 2:
TYPE IN THE FOLLOWING:
@echo off
title MY PROGRAM
color a
echo WELCOME
echo.
echo 1.)START
echo 2.)EXIT
echo.
set /p var=YOUR CHOICE:
if %var%==1 goto HELLO
if %var%==2 exit
:HELLO
cls
echo PLEASE CHOOSE AN OPTION
echo.
echo 1.)OPEN GOOGLE
echo 2.)OPEN EMAIL
echo 3.)SHUTDOWN COMPUTER
echo 4.)EXIT
echo.
set /p var=YOUR CHOICE:
if %var%==1 start www.google.com
if %var%==2 start www.gmail.com
if %var%==3 shutdown -s
if %var%==4 exit
pause
exit
Step 3:
Save as program.bat
3 Comments
Tip 4 years ago
its also good practice to do this in order to prevent syntax errors like just pressing enter without entering anything or just pressing space and then enter. If you just press enter, "var" will be null and you cant compare a null variable to a string or a number. Now the file knows that its an empty string and will be able to compare the two and wont close the batch file.
set /p "var=YOUR CHOICE:"
and also do it with the if statements
if "%var%"=="1" start www.google.com
along with what everyone else said about putting an else statements or something underneath it to tell the user that they typed in an invalid entry
5 years ago
I'm not being rude, but you made 2 mistakes:
1. You should put a else statement after choices
2. Who needs to shutdown their computer through a batch file?
8 years ago on Introduction
This program works, but you may want to add an else statement after the choices. Currently if you enter a 3 in the first choice then it goes to :HELLO