MODERN
BATCH
SCRIPTING
Prince Patel
From Desi Programmer
Modern
Batch
Scripting
A Basic
Guide
Prince Patel
From Desi Programmer
From the Author
I, Prince Patel Has
Written This Book To
Make It Easier To
Understand Batch
Scripting.
While This Is A Modern Time Of Windows
Powershell But Still Batch Scripting Is Something
That Is Still Much Used. Batch Scripting Is Cool It Can Run Everywhere. If You
Want To Use Linux
Or If You Are Interested In Hacking Or If You Do
Use The Windows Command Shell Quite Often
Then You Must Understand Batch Scripting
Because Using This You Can Run Multiple
Commands At A Time And The Same Is Done In
More Efficient Way In Linux Using Shell. So With
This Ebook We Try To Understand The Basics Of
Batch Scripting Without Going Much Deeper Into
The Old Concepts
This Book Is A Solo Work Of Prince Patel,
Hence Producing This Book In Any Form
Or Selling This To Other Is Prohibited. This
May Call For Legal Action. Also A Real Copy
Of This Book Is Always Stored With Me,
And If You Find Any Information Entered
In This Book Or You Yourself Alter The
Information, Even Then This Is Offensive.
And If You Find This Book With Error You
Can Suggest Me On My Email Or On My
Facebook Profile.
Suggestions Are Always Welcomed.
Message Me
What's Desi Programmer?
Desi Programmer Is A Platform To Learn
Real Life Technology, Programming,
Hacking And Much More Connected To
Internet Free Of Cost From Youtube,
Facebook, Instagram And Website. We
Provide Free E-book Quizzes And Much
More To Enhance Your Technical.
Programming And Hacking Knowledge In
Real World.
Be With Us
Learn With Us
Build With Us
Connect With Us
Youtube English
Youtube Hindi
T A B L E O F C O N T E N T S
Basic Commands
Printing Text
Variables & Input
If statements
Try It Yourself
Advanced If Statements
If-Else Block
Nested If Else
Loops
Debugging
Special Batch Files
To Do
Quiz
Before We Begin...
Before We Begin Let Me Tell You That
Even Though The Commands In This
Book Or Those You Must Copy In Your
Notepad And Experiment, To Learn And
Trust Me You Should Feel Free To Do
That, But On The Other Side Many
Commands In This Book Might Harm
Your Computer A Note Is Written Every
Time I Use Such Commands. Hence Use
Them On Your Own Risk. I Am Not
Responsible For Any Harm To Your
Computer After Using Such Commands.
~Author☺
Modern Batch Scripting
Before We Begin Let's First Copy The Following
Command In Your Notepad And Save It With
Any Name With .bat Extension. Then Run
Them And See The Magic.
1. Save this bat file as profiles.bat (you can
choose any name)
@echo off
netsh wlan show profiles
pause
Now Run this and see what happens.
1. Save This File As Folders.bat
@echo off
d:
md Important
cd Important
md Videos Images Files
Modern Batch Scripting
cd Images
md New Old
cd..
cd Videos
md New Old
cd..
cd Files
md New Old
pause
Now Run Both The Files, You Can See That
After Running The First File You Can Check
All The Profiles That You Have Ever Connected
With Your Desktop Or Laptop. And After
Running The Second File You Can See That
You Have Created A Folder Called Important In
Your D Drive With Three Sub-folders In It, And
Again Two Sub-folders In Each Of The Three
Sub-folders. If You Try To Do This Process With
You GUI Or Command Line Interface, Then You
Can See That It Takes More Time But With
Modern Batch Scripting
Some Simple Lines Of Codes You Can Do This
Very Soon, Almost In Some In Seconds. So This
Is Where The Batch Scripting Arises.
So Now Let's Try To Understand The Concepts.
Modern Batch Scripting
4
Environment
To Run Each And Every Batch Script We Use
The Windows Command Shell That Is Windows
Command Prompt.
The Following Images Shows How the CMD
Looks Like.
Modern Batch Scripting
Click On The Links Below To Watch Practical
Videos On Understanding The Windows
Command Shell Popularly Known As Windows
Command Prompt.
Watch Now. ☺☺
We Can Launch The Command Methods By The
Following Two Easy Ways.
1. Click On START>ALL PROGRAMS>CMD
2. Press WIN+R Key And Type CMD In The
Search Box. Hitting Enter Will Open The
Command Prompt.
Modern Batch Scripting
Creating Batch Files
Creating Batch Files Is Very Easy. You Can Do
This With Any Text Editor Like Ms Word,
Wordpad And Notepad. But We Frequently
Used Notepad Or Notepad++ Only. So Go To
Start> Programs>Notepad.
Clicking On This You Can Launch Notepad On
Your Screen To Type Commands.
Well Batch Files Creations Doesn't End With
This, Because You Have To Save These Files
With An Extension Of .bat Only Then These
Files Will Become Batch Files And Clicking On
Them Will Launch Them Through CMD.
Editing Batch Files Is Again Quite Easier, Just
Right Click On The Batch File And Then Select
Edit. In Older Versions Of CMD Or Windows
You Can Even Type The Command EDIT Space
The Batch File Name To Edit The Batch File.
Modern Batch Scripting
Text On Screen
Text On Windows Command Prompt Screen
Can Be Printed By Using Echo Command. Use
The Echo Command In The Following
Manner To Print The Text On Your Screen.
echo I Am Learning Batch.
While Batch Files Don't Have Special Escape
Characters For Tab Or Newline, So To Create
Spaces Or Tab Spaces You Must Either Use The
Tab Key Order Space Button.
And To Enter A New Line You Must Use
Echo.
Command.
Modern Batch Scripting
Two Important Commands
Now First Let's See Two Important Commands.
They Are Cls And Pause.
Using Cls You Can Clear The Screen. So While
Writing Batch Files If You Want To Clear The
Screen For The Next Upcoming Test You Can
Use Cls. While Cls Is Not Of Much Use But
Pause Is Very Necessary.
Even In Simple Batch Files Just Typing Echo
This Is A Batch File Will Not Show You The
Text On Screen, Because The Cmd Will Exit
Itself. So For The Command Prompt To Wait
Till You Ask It To Exit, You Must Use A Pause
Command. Then You Will See A Text Like
Press Any Key To Continue And In This Way
you Can See Your Text Or Your Program
Running.
Pause Command Can Be Used Multiple Times
So That You Can Give Inputs Look At Outputs
And Much More
Modern Batch Scripting
comments
Comments Are Very Necessary In Any Kind Of
Programming Or Scripting To Tells The User
About The Functions Of The Following
Command Or Block Of The Statements. Another
Important Use Of Comments Are That They Do
The Work Of Documentation. Hence
Commenting In Batch Scripting Too Is
Necessary. There Are Two Methods To Write
Comments In Batch Script. The First One Is
Using The Rem Command That Is Remarks
Command Following By Your Comment And The
Another Method Is To Use Two Semicolons (::)
Followed By Your Comments.
Following Is An Example Explaining Both Of
These
rem This is a comment
:: This is another comment
Modern Batch Scripting
10
Watch Practical Videos For
Better Understanding.
Click To Watch.
Modern Batch Scripting
11
Variables
Variables Are Actually The Most Important
Part Of Programming Or Scripting Because
They Let Us Interact With The User. So In
Batch Scripting Too We Have Variables. Now
Let's See How Can We Define Them, Use Them,
And Take Inputs Using Them. Defining
Variables In Batch Scripting Is Very Easy All
That You Have To Do Is To Use Set Command
And Then A /p Followed By Your Variable
Name With A Equal To (=) Sign And The Text
To Prompt Without Any Spaces Between Them.
Remember You Can't Use (=) In The Variable
Name.
Below Is A Sample Of Variable Naming And
Using. Here Var Is The Variable Name And
"Enter A Number" Will Be Prompted When You Run The Batch Script.
set \p var=Enter A Number
Modern Batch Scripting
12
Evaluating Expressions In Batch Scripting Is
Not That Necessary, But It Still Just As For
Understanding We Should Note That Set \a
Calculates The Result, Using Set \a In The
Following Manner, Will Give Out The Result.
set \a %calc%=%var% + 1
Remember Set \a Uses Another Variable To
Store The Result.
An Awesome Point About CMD Is That,
Without Entering Two Numbers And Then
Adding Them You Can Simply Enter
Expression To Evaluate The Value. While We
Are Not Going To Go In Much Logical
Programming Or Calculations So We Will Not
Go Deeper In This Topic.
Modern Batch Scripting
13
As For Now We Understood How To Take
Input From The User. But To Give The Output
To Users Using The Variables We Have A
Different Method. To Print The Value Of A
Variable We Have To Use 2 "%" Before And After The Valuable Name With The
Echo
Command. I Have Shown You An Example Of
The Same Below.
echo This is %var%
Var Named Variable That I Used In Above
Example If The User Enters 5, Using This Way
Of Echo Command You Can Give An Output
On The Screen Stating That You Entered 5.
echo you entered %var%.
Modern Batch Scripting
14
Two important commands
Now First Let's See Two Important Commands.
They Are Cls And Pause.
Using Cls You Can Clear The Screen. So While
Writing Batch Files If You Want To Clear The
Screen For The Next Upcoming Test You Can
Use Cls. While Cls Is Not Of Much Use But
Pause Is Very Necessary.
Even In Simple Batch Files Just Typing Echo
This Is A Batch File Will Not Show You The
Text On Screen, Because The Cmd Will Exit
Itself. So For The Command Prompt To Wait
Till You Ask It To Exit, You Must Use A Pause
Command. Then You Will See A Text Like
Press Any Key To Continue And In This Way
you Can See Your Text Or Your Program
Running.
Pause Command Can Be Used Multiple Times
So That You Can Give Inputs Look At Outputs
And Much More
Modern Batch Scripting
15
goto
While In Many Programming Languages,
Programmers Always Skip The Goto Command
Or Statement But In CMD Goto Is Actually
Very Necessary To Create Or Execute A
Looping Situations Easily. You Will
Understand That Further, But For Now To
Understand The Use Of Goto Command Just
Look At The Illustration Below.
goto a
:a
echo There You came.
The Text After Got States Where You Want To
Go And To Declare Your Gooto Statement Or
The Commands Under The Go To Statement,
You Can Write A Semicolon Followed By The
Go To Variable Name And Then On The Next
Line You Can Write All The Other Commands.
Modern Batch Scripting
16
if statement
If Statements Are Very Necessary To Make
Decisions In Any Kind Of Programming
Languages And So They Do In Batch Scripting
Too.
Using If Command In Batch Scripting Is
Actually Very Easy. You Can Use The
Following General Syntax Stated Below To Use
If Command.
if variable "operator" "value" command Now Usually We Make Comparison
Between
Have Two Variables, A Variable And Constant.
So You Can Use The Folloewing Below
Illustration Followed By The Commands That
You Want To Execute If This Statement
Becomes True.
if %var%==5 echo hii
Modern Batch Scripting
17
A Work
Now That We Have Understood Some Basic
Concepts In Batch Programming Like Printing
Text, Using Variables, User Inputs, Outputs,
Decision Making, Goto And Pause Statement.
Just Copy The Below 2 Code Of Batches Codes
Again Save Them With Any Name But .bat
Extension And Run Them. This Are Simple
Programs That Actually Asked You For An
Input And Then Work According To It. What I
Want To Say Is That Just Copy This Codes, Run
Them Normally And Then Do Experiments
Eliminating Or Adding Any Of The Commands
And See How The Programs Gets Affected.
Only This Using This Method Only You Can
Actually Learn More Which Will Be Extremely
Helpful And Will Give You More Logical
Thinking Ability.
Modern Batch Scripting
18
CODE 1
@echo off
:start
echo.
echo Hii This A Code By prince Patel
echo This code prints five random numbers.
echo Enter 1 to print in grey
echo Enter 2 to print in red
set /p var=Enter Your Choice.
goto %var%
:1
cls
Color 08
echo %random% %random% %random% %random%
%random%
pause
cls
goto start
Modern Batch Scripting
19
:2
cls
Color 7C
echo %random% %random% %random% %random%
%random%
pause
cls
goto start
Modern Batch Scripting
20
CODE 2
@echo off
:start
echo Another Code By prince Patel
echo.
echo enter the drive to list it's directories
set /p var=Enter the drive letter.
goto %var%
cls
:c
c:
dir
pause
cls
goto start
:d
D:
dir
Modern Batch Scripting
21
pause
cls
goto start
:e
E:
dir
pause
cls
goto start
:f
F:
dir
pause
cls
goto start
:exit
exit
Modern Batch Scripting
22
The First Batch File Is To Print 5 Random
Numbers In Two Different Colours. Copy The
Code Save It With A Bat Extension And Try
Erasing Or Using Your Own New Commands To
Check How The Program Behaves.
The Second Batch File Is To List Out All The
Directories I.e Files Available In A Particular
Drive. You Have To Enter Your Drive Letter
And This Script Will List Out All The
Directories Available In That Fine Drive So Try
This Too And Have Fun.
Modern Batch Scripting
23
if, else, if-else statements
Decision Making Is Quite Easier With If Else
Statements And In A Scripting We Can Easily
Create A Menu Driven Program Using If Else
Statements. The General Working Form Of
This Statement Is That If The Condition Is True
The Commands Of If Block Get Executed And If
The Condition Is False Then Either The Else
Block Executes Or The Other Commands Work.
So Earlier We Noted How To Use If Statements
But In This Section We Will Learn About Some
Advanced Functions Of If And If Else. So Using
If We Can Compare Variables And Their Values
Using Some Operands. A List Of Those Are
Operands Is Given Below.
Modern Batch Scripting
24
Relational Operators
EQU : Tests the equality between two objects
NEQ : Tests the difference between two objects
LSS : Checks to see if the left object is less than the right operand
LEQ : Checks to see if the left object is less
than or equal to the right operand
GTR : Checks to see if the left object is greater
than the right operand
GEQ : Checks to see if the left object is greater
than or equal to the right operand
Logical Operators
AND : This is the logical “and” operator
OR : This is the logical “or” operator
NOT : This is the logical “not” operator
Modern Batch Scripting
25
These Are Used In CMD. Also Note That We
Use To Equal To Signs To Say That This Is
Exactly Equal To That And This Is Not As
Same As The Single (=).
While Using If Else Statements A Key Thing Is
That You Must Use Brackets After The If And
Else Or The Program Will Not Work Well And
It Made Show Error. Also Another Thing To
Note Is That The If Else Statement Should Be
Written In A Single Line.
Given Below Is An Example of Simple If
Statement.
@echo off
echo Welcome To Desi Programmer.
set /p var=enter value
if %var%==1 start cmd.exe
pause
exit
Modern Batch Scripting
26
The First In This Batch File This Batch File
Asks The User To Input A Number And If The
User Inputs One Then This Program Will Start
Command Prompt.
@echo off
echo Guess The value of 10/2.
set /p var=enter value
if %var%==5 (echo "You guessed it correct") else (echo "So Sorry")
pause
exit
Second Program Will Ask The User To Enter A
Number And If The Number Entered Is 5 Then
It Will Print "You Guessed It Correct" And If It Enters Any Other Number Then
It Will Print
"So Sorry".
Modern Batch Scripting
27
An Special Case Of If Statement Is The "If-
defined" Statement Which Is Used To Test For
The Existence Of A Variable. Following Is A
General Syntax For The Statement That Can
Be Used.
if defined variable command
Also Given Below Is A General Example Of
How The If Defined Statement Should Be Used.
@echo off
set var1=variable is defined
set var=variable
if defined var (echo "Var named Variable
defined") else (echo "var not defined") pause
This Program When Executed Searches For
"Var" Named Variable And Since Present Prints Var Named Variable Defined.
Modern Batch Scripting
28
Another Important Other Special Case Of If
Statement Is If Exists Which Is Used To Check
The Existence Of A File.
Following Is The General Syntax Of The If
Exists Command.
If exist anyfile.ext do_this
And Then Is An Example To Check The Special
Statement.
@echo off
if exist C:\Users\intel\Desktop\non.txt (echo
"File exists") else (echo "doesn't exists") pause
In This Above Program, Since The Same
Non.txt File Doesn't Exists In That Particular
Location In Your Computer, It Will Hence Print
'file Doesn't Exists".
NOTE : if-else Command Is Written In same
Line.
Modern Batch Scripting
29
looping
Looping To Is Very Necessary In Programming
And Scripting To Execute Some Block Of A
Statement Multiple Times. We Can Write
Looping In Our Batch Script And The Method Is
Again So Simple But Since We Are Not Going
To Go Through Logical Programming We Will
Discuss One Method Of Writing Loop That Is
The For Method.
Below Is A General Statement Of How We Can
Move Through A Range Of Values To Execute
A Set Of Commands Using For Command.
FOR /L %%var IN (start,step,end) DO
command
NOTE : The Entire Command Is In Same Line.
Don't Get Confused To Press Enter Key.
Modern Batch Scripting
30
Hear The /L Switch Is Used To Show That The
Loop Is Used For Working Between Ranges.
The In Part Contains Three Values That Is The
Lower Limit, Increment, And The Upper Limit,
Which Means That The Loop Will Start From
Lower Limit And Will Move To Upper Limit
Changing Each Time By The Increment Value
And The Do Something Block Is Used To Define
The Statements That We Want To Execute
Through Of The Loop.
Sometimes Goto Statement Is Also Used To
Write Loops, But Still This Looping Method Is
Something We Must Use. If You Are Wondering
How We Use Goto Command For Writing Loops
Then You Must Remember The Matrix Batch
File That We All Used To Play With. It Is Also
An Example Of Infinite Loop Using Goto.
On The Next Page I Have Given An Example Of
Loop Using For Command.
Modern Batch Scripting
31
The Numbers Must All Be Within The Range Of
32 Bit Signed Integer Numbers (-2,147,483,648
Through 2,147,483,647)
In Addition To Integer Numbers, Hex And Octal
Numbers Can Also Be Compared Within
Certain Limits.
If The Start,step,end Are Left Null Or (0) Then
The Command Will Loop Indefinitely, Ctrl-c
Will Abort The Whole Script.
Also Note That The Var After /l Should
Contain One Letter Only.
Given Below Is A Simple Illustration. In This
Program A Number Is Entered by The User And
The The Loop Is Created From That Number
Till 10 Printing A Random Number.
Modern Batch Scripting
32
@echo off
set /p v=enter a number less than 10.
FOR /L %%v IN (%v%,1,10) DO echo %random%
pause
Modern Batch Scripting
33
files
In A File In Batch
Echo Text > Filename.txt
This Command Will Create A File In The Same
Directory Of Batch And Then Place The Hi In
It.if Uses Two Arrows It Will Place Two Hii Text
In The File.
You Can Even Use A Variable To Store That
Variable In Your File, Using This Method We
Can Create A File And Save Our Data To It.
Now We Will See About Accessing Data From
That Text File. Accessing Data From Text File
Is Again Quite Easy We Will Use The For
Command With /f And Then We Will Extract
Particular Text From That File And Then
Assign That To Other Variables And Then
Modern Batch Scripting
34
Either Printed Or Will Check If According To
Our Situation And Then Do Whatever We
Want To Do With That.
Given Below Is An Illustration Of How To Save
Our File And Then Extract Our File Text.
@echo off
echo hii > text.txt
for /f "delims=" %%a in (text.txt) do (
set text==%%a
if %text%==hii (echo "yeah i got it") else (echo
"Nope")
pause
In The Above Program We Create A Text File
With The Name Text On Our Deskstop Because
I Am Working On My Desktop Directory And
Then I Will Save A Text Hii To It. Again I Will
Modern Batch Scripting
35
Extract That Text Hii And If The Text Will Be
Equal To Hii Than An Output Will Be Yeah Got
It. Now You Can Replace The Text Hii To Hello
And You Can See That You Get The Else Block
Executed.
I Am An Independent
Writer.
Connect me To Support
Me.
Modern Batch Scripting
620
debugging
Now Before Proceeding Further We Will Talk
About The Problem That Is Finding Bugs Or
Errors In Your Batch File. If You Double Click
On Your Batch File That Is Executed And Still
You See That Other Than Running The File
Your Cmd Window Disappears Within Seconds
Then This Means That There Is A Error In Your
Batch File. Now Finding This Error Is
Sometimes Very Hard So We Will Use This
Method To Find That Error Using Command
Prompt.
For This You Will Have To Open Your
Command Prompt And Then Navigate To The
Directory Where You Have This File Saved.
Now Just Type The Filename With Extension
And Hit Enter. You Can See The Errorin Your
Program And Other Things To Note Here Is
That If One Or Two Commands Of Your
Programs Are Running Successfully Done
First
Modern Batch Scripting
37
It Will Execute Those Commands And Then It
Will Identify The Error This Is Quite Helpful In
Pointing Out Error At Exact Points In Long
Programs.
Given Below Is An Illustration Using Which I
Will Tell You The Error In Program Using
Command Prompt.
@echo off
echo hii
set /p v=enter a expression
if %%v=1 (start text.exe)
pause
Now This Program Is Executed And Will First
Print Hii And Then The Window Command
Prompt Screen Will Either Disappear Or It Was
So That Something Was Unexpected This
Time.
This Means That There Is An Error Is This
Modern Batch Scripting
38
Program, Now You Might Be Able To Feel Ok To
Watch The Error At Once But If You Are
Unable To Then Just Open Command Prompt
Move To The Directory Where This Batch File
Is And Start The Batch File That Is Type The
Bat File Name With .bat Extension And Then
Run Hit Enter.
You Can See That It Prints Hi Then Ask You To
Enter An Expression But When You Continue
That It Shows An Error.
Here You Can Understand What Was
Unexpected And Can Go To Fix This.
Modern Batch Scripting
39
To Learn About
Converting .bat To .exe
and To Learn Encryption
And Decryption Using
Batch Files
Click Here.
Modern Batch Scripting
40
Get More From Desi
Programmer
> Tutorials
>E-Books
>Magazines
>Inspiration
>Tech news
>Quizzes
And Much More...
PLAY THE C
PROGRAMMING
QUIZ
click this
Modern Batch Scripting
41
With This We Have Understood Many Topics In
Batche Scripting Like Printing Text, Using
Variable,s Making Decisions, Using Loop, The
Goto Statement, And Some Basic Commands.
Now Working With Cmd, We Are Eligible To
Write Batch Scripts And Execute Them. With
This We End The Discussions On Batch Script.
While They Are Still Many Topics In Batch
Tutorials But As Ihave Already Told That
Batch Scripting It Something Not More In Use
Hence Going In The Deeper Branches Of
Logical Batch Scripting Is Actually No More
Necessary. It Is Same As Learning Graphics In
C Which Is No More Useful. Still We Have Read
This E-book Because Using This Batch Scripts
Still We Can Make Some Good Jokes On Our
Friends, We Can Make Our Own Programs To
Make Our Own Work Easy And Even We Can
Write Some Good Programs And Share It With
Your Friends Or Sell It To Earn Some Money. I
Have Left A Link For You All To Learn How To
Modern Batch Scripting
42
Convert Your Bat Script In An Exe File But Till
Now All We Have Learnt Is Actually Enough
To Write Some Common Batch Scripts. Go
There To Learn More Practical Topics On Batch
Scripting Like How To Run A Script Every Time
You Turn On Your Computer, How To Crash
Your Computer, How To Make Work With Your
Computer, How To Test Your Antivirus, How To
Make An Application On Turning Off Or On
Windows Hotspot, And Much More. Visit Our
Practical Facebook Page Or Youtube Channel
For Videos. Now Have A List Some Of The
Important Batch Files Using Which You Can
Have Fun, Amaze Your Friends Or Do A Lot Of
Work On Your Own Also. At The End You Will
Find A Link For Quiz In That Is Scripting I Hope
You Will Enjoy This Is Small Test In Batch
Scripting To Check If Your Knowledge Has
Enhanced To Good Levels Or Not.
All The Best For Writing Scripts
Keep Learning And Share It With Your Friends.
Modern Batch Scripting
43
First Try This Awesome File To Amaze Your
Friends.
@echo off
:lolipop
echo.
echo Hello there, how are you?
set /p feeling=
if %feeling%== bad goto sad
if %feeling%== good goto lol
goto lolipop
:lol
echo.
echo good,now what is you're name?
set /p name=
echo That's a great name %name%!!! I love it!!
echo, anyways, time to get serious %name%,
what is your favorite team?
set /p team=
Modern Batch Scripting
44
echo what is your fave internet browser?
set /p browser=
goto fun
:fun
echo.
echo you lied to me %name%, you don't love
%team% or %browser%!!! now you will
pay!!!
goto shutdown
:shutdown
echo.
echo I will now proceed to delete all your
computers critical files.
echo ready?
set /p answer=
if %answer%==yes goto delete
if %answer%==no goto sad2
:sad
Modern Batch Scripting
45
echo.
echo Sorry to hear that buddy. :'(
goto lol
:delete
color 0D
echo.
echo ok,chow!!!
echo {0A}%random% %random% %random%
%random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random%
%random% %random%
goto random
:random
color 0A
echo.
Modern Batch Scripting
46
echo %random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random%
%random% %random%
goto werdy
:sad2
echo.
echo too bad, you lied to me!!! TTYL!!!
echo i will talk to you soon right?
set /p what=
if %what%==yes goto delete
if %what%==no goto delete
goto delete
:werdy
Modern Batch Scripting
47
color 2A
echo.
echo %random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random% %random%
%random% %random% %random%
%random% %random%
goto random
Source : The Internet
Modern Batch Scripting
48
Create Special Matrix Effect
@echo off
:a
color 2
echo 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 1 0
0 0 1 1 1 1
ping localhost -n 1 > nul
echo 1 1 0 1 1 1 0 0 0 1 0 1 a f h 0 0 0 1 0 1 1 0 0 1 1 1 0 0
1 0 1 0 0 1 1 0
echo 1 0 0 1 1 0 9 8 1 2 0 1 9 9 2 1 1 1 0 0 1 0 1 1 1 0 1 1 0
1 0 0 0 1 0 1 1
ping localhost -n 1 > nul
echo 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0
01 0 1 0 0 1 0
ping localhost -n 1 > nul
echo 1 0 1 1 1 0 1 1 0 9 1 1 2 1 1 0 9 1 0 5 7 7 8 7 8 1 3 2 1
2 1 2 3 2 1 3 4
ping localhost -n 1 > nul
echo 1 1 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1 1 4 1 2 1 1 2 0 1 0 1 2
2 1 0 1 1 0 1
goto a
Modern Batch Scripting
49
Make Your Computer Speak
Dim message, sapi
message=InputBox(“What do you want me to
say?”,”Speak to Me”)
Set sapi=CreateObject(“sapi.spvoice”)
sapi.Speak message
Save This As Text.vbs
Open and See The Magic.
Let's Make Keyboard LED Dance
Set wshShell
=wscript.CreateObject(“WScript.Shell”)
do
wscript.sleep 100
wshshell.sendkeys “{CAPSLOCK}”
wshshell.sendkeys “{NUMLOCK}”
wshshell.sendkeys “{SCROLLLOCK}”
loop
Modern Batch Scripting
50
Save the file as Dance.vbs
Click the file and your all three LED lights will
start dancing.
To stop, Shut down or Log off your PC.
Annoy Someone By Repeting Messages
@ECHO OFF
:BEGIN
MSG * HI
MSG * ARE YOU FINE?
MSG * I AM!
MSG * LETS HAVE FUN TOGETHER!
MSG * BECAUSE YOU HAVE BEEN O-W-N-E-
GOTO BEGIN
Modern Batch Scripting
51
Disturb Someone By Opening Any Application
Like Noteone Constinuosly
Note : It May Crash Computer
@ECHO OFF
:TOP
START
%SYSTEMROOT%\SYSTEM32\NOTEPAD.EXE
GOTO TOP
Modern Batch Scripting
52
So Now We Have Understood Batch
Scripting And We Even Had A Look At
These Commands. To Find More
Interesting Topics Like
How To Start A Bat File Everytime You
Boot Your Computer
Creating Of Private Folder Without Any
Other Software
And To Create Batch Scripts With Ascii
Text
Visit My Facebook Page Or Youtube
Channel.
KEEP LEARNING
KEEP SHARING