Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
103 views

Batch File Programming

This document provides an overview of batch file programming and common commands used in batch files. It discusses batch file modes, operators, subcommands, switches, and examples of commands like DEL, ECHO, PAUSE, SET, redirection, path shortening, and conditional logic. A table lists many common batch file commands and their functions, such as DEL, XCOPY, DIR, MKDIR, REN, REPLACE, and COPY for deleting, copying, listing, creating, and renaming files and folders.

Uploaded by

Deol Peter
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Batch File Programming

This document provides an overview of batch file programming and common commands used in batch files. It discusses batch file modes, operators, subcommands, switches, and examples of commands like DEL, ECHO, PAUSE, SET, redirection, path shortening, and conditional logic. A table lists many common batch file commands and their functions, such as DEL, XCOPY, DIR, MKDIR, REN, REPLACE, and COPY for deleting, copying, listing, creating, and renaming files and folders.

Uploaded by

Deol Peter
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

BATCH FILE PROGRAMMING ::

*********************************
TWO MODES : INTERACTIVE MODE AND BATCH/SILENT MODE
IN INTERACIVE MODE : AS THE COMMAND IS TYPED IN THE PROMT ASKS FOR THE USER TO I
NTERACT IN THE BATCH MODE AFTER THE COMMAND IS TYPED IN THE USER IS NOT REQUIRED
EG :: DEL COMMAND
del a ;used for deleting the contents of a folder->once this command is typed in
it asks for a confirmation
del /q a ; here no confirmation is asked the '/q' switch runs the command in the
batch mode
when saving : save the file as a .bat extension from a notepad
two types of commands :: internal and external commands : internal -> commmands
which are default to all systems
and external -> commmands which are system specific
Batch Operators : Usual operators
Operator precedence : (),/,*,%,+,-
Sub commands and switches
eg : net users a a /add : here 'net' is the main command,'users' is the sub-comm
and,/add is the switch : basically the command adds a new user 'a' with a passwo
rd 'a'to the total users of the computer
COMMAND LIST
*****************
del :: commmad to delete the contents of a folder
/q : switch to run in batch mode
echo :: print the following command
pause :: to wait for the user's intervention at the end of the program
set :: for operations
/a : to do arithmetic operations such as addition etc - set /a 5+5 gives
10 as output
> :: Redirection of output
eg : echo hello > a.txt ; outputs hello to the text file a.txt ; NB : if a.
txt is not available, it creates it
~ :: Shortening of the path names : eg : documents folder can be represent
ed by docume~1 : NB : Apply '~' after 6 characters
&& :: Multiple command operation in a single line
| :: To give the output of one command as the input to another
eg : echo y | del *.txt ; gives a 'y' as confirmation whenever the del comm
and is called upon
help :: to get help
/? :: to get help on a specific command eg : net /? : gives help on a speci
fic command
REM :: For remarks
color :: for setting the color of the cmd display : eg :: color 1 2 :: first n
umber is the background color and the second one represents the foreground color

title :: To change the title of the cmd window


propmt :: Changes prompt
cls :: Clear Screen
date :: To change the current date
: /t : displays the current date
time :: To change the current time
: /t : displays the current time
start :: to start a new program with options
: /d : Starting directory of the shell
: /min : To start in the minimised mode
: /max : To start in the maximimsed mode
: /separate & /shared : To assign seperate or shared memory
: /low;/mormal;/high;/abovenormal;/belownormal;/realtime :: Setting prio
rity
: /wait : waits till the program terminates
: /b : opens up new command prompt without a new window,when you type ex
it it exits out of the new prompt
exit : To exit from command prompt
call :: Used to call another batch program
tasklist:: Lists out the entire tasks and processes
/s : To specify the remote machine to connect with
/u : Username
/p : Password
eg : tasklist /s sys1 /u admin /p admin
/m : Display the corresponding .dll files
/svc:displays corresponding services
/v : To display the verbose information
/fi: To filter the results
Filter parameters : eq,ne,gt,lt,ge,le
FILTER NAMES VALID VALUES
*****************************
STATUS RUNNING or NOT RESPONDING
IMAGENAME IMAGE NAME
PID PID VALUE
SESSION SESSION NUMBER
SESSIONNAME SESSION NAME
CPUTIME CPU TIME : HH:MM:SS
MEMUSAGE MEMORY USAGE IN KB
USERNAME USERNAME
SERVICES SERVICE NAMES
WINDOWTITLE WINDOW TITLE
MODULES DLL NAME
EG : TASKLIST /FI "STATUS EQ NOT RESPONDING"
taskkill :: To kill a task
eg : taskkill /s 192.168.1.1 /u a /p a /im a.exe : to kill process a.exe in the
system 192.168.1.1 with username a and password a
/im : To end imagename
/f : To forcefully terminate
/pid: To end the process with the given id : eg: taskkill /f /pid 001
/t : to end all the corresponding threads and child processes
/fi : Same as in the tasklist
label :: To change the label of a drive eg : label D: Softwares -> Replaces D:
drive name with Softwares
tree :: Lists every details and files in a directory in tree format
/f : For an elaborate tree
/a : For displaying in ascii characters instead of extended characters
ver :: Displays the version of the os
type :: Displays the contents of a file
convert :: To convert filesystems
eg : convert c: /fs:NTFS -> /fs : The filesystem to convert to is specified by
/fs switch
shutdown::Variants of shuttingdown the system
-s : Shutting down
-r : Reboot System
-l : Log off
-a : Abort shutdown
-t : To specify time for shutting down : Time should be entered in seconds
-c : To specify comments for shutting down : eg : shutdown -s -c "Shutting Do
wn"
-i : To open remote shutdown dialog box
/m : To remote shutdown a system whose address is known
eg : shutdown /m 101.101.1.1 -r
/f : To forcefully terminate a program and shutdown
at :: To schedule an operation
eg : at 101.101.1.1 8AM "notepad.exe"
/delete ; Switch to delete an already scheduled task
eg : at 556 /delete :: To delete a task with job ID 556
at /delete /yes : To delete all tasks without confirmation
/interactive : to make the scheduled tasks more user interactive
/every : to schedule on a routine schedule
eg : at 5:00PM /every:M,T,TH,S,SU a.exe : Here we have entered days
/next : to schedule for next items : eg: at /next:1,10,20 a.exe : Here we ha
ve entered dates
CONDITIONAL STATEMENTS
*****************************
IF: if errorlevel 1 ( echo failed ) else ( echo success )
dir : Lists the directories and the files in a folder
/a : Attribute switch - parameters -> r : readonly files,h : hidden,d :
directories,s : system files,a : files ready for archiving,i : not content index
ed files : eg : dir /as - to display all the system files
/b : To display the bare information alone
/c : To display the file sizes with seperator;/-c : To display the file
sizes without seperator
/d : To display the file extensions alone
/l : To display the results in lower case
/o : To display the output in the required format : s:size;n:name;e:exte
nsion;d:date/time;g:group directories first
/p : If output overflows an existing page the user is prompted to press
a key
/q : Displays the owner of the files
/s : Displays detailed information
/t : To create logs : c:Creation date;a:Accessed date;w:Write date eg: d
ir /tc
/w : For a wide list
/x : To display in small names : in 8dot3
/4 : To display dates in 4 digits
mkdir : make directory : MKDIR A\B\C ; MKDIR "MY COLLECTIONS" -> IF SPACE IN
THE NAME USE DOUBLE QUOTES
RMDIR : REMOVE DIRECTORY : /S : USED TO DELETE ALL SUB-DIRECTORIES;/Q : USED T
O DELETE IN QUIET MODE -> NO PROMPTING THE USER
CHDIR : CHANGE DIRECTORY
NB : TO GET TO THE DRIVE WINDOW AFTER CHANGING TO A VARIED DIRECTORY IN THE DRIV
E SAY IN DRIVE F:;TYPE IN CMD : F:\
REN : RENAME EG: REN A B->RENAMES A DIRECTORY WITH NAME 'A' AS 'B'
replace : similar to copy commmand eg:replace c:\a\a.txt c:\b /a -> Copies a.txt
from folder a to folder b.Here the /a switch is used to specify that
a new copy is to made.Without this /a switch in most cases nothing occurs.
/p : Asks for user confirmation. /r : Copy read only files. /s : Used to
copy files in all the sub-directories. /u : Used to append to a
n existing file or update./w : wait for the user to enter a disk etc.
copy : NB:You cannot copy directories as such : if at all directories are men
tioned only its contents are copied to the destination folder eg :
copy c:\a.txt d: -> Copies a.txt to d:
/a : Copy files in ascii mode;/b : save files in binary mode;/d : destti
nation folder is decrypted;/v : verifies if files are written properly;/n :
create short file names;/y : prevent confirmation if a file already exists;/-y :
asks for the neede confirmation;/z : to copy networked files
xcopy : Better than copy as it has got much more options.
/d : Used to copy files which are modified after a particular date : eg
: xcopy /d:m-d-y c: f: ->here m-d-y is substituted with the required da
te.
/exclude : Used to restrict copying certain type of files : xcopy /exclu
de:.txt c: f:
/p : To propmt the user to create a new folder if copying to a non-exis
tant folder
/s : Copies all the sub-folders etc which are not empty
/e : Copies even the empty folders
/v : To verify if copying was done properly
/w : To ask for prompting to copy
/c : To continue copying even if an error occurs
/q : To prevent the display of the names of the items being copied
/f : To display the full source and destination names of the items being
copied
/l : To display the names of the files that are supposed to be copied
/g : To copy encrypted files into folders that does not support the encr
yption
/h : copying files that are hidden and has system attribute
/r : Copying files that has read only attribute.
/t : Creates a directory structure
/u : To copy files already in the destination directory
/k : To copy the attributes also in usual case the attributes are resett
ed in the case of the new copied file
/n : Copies the file ownership and access control attributes so that the
security remains the same
/x : In addition to the /n settings it also copies the audit settings
/b : To create a shortcut
/y : To ask for confirmation ;/-y : To not ask for confirmation
/z : To copy networked files
pushd : Keeps the current working directory or the required directory in the s
tack until it pops out
popd : Gets to the earlier directory
eg : rem "Current working directory is c:"
pushd d:
rem " Goes to directory d:"
popd
rem " Takes you back to directory c:"
NB : dir a -> lists the files in the 'a' folder
NB : del a -> does not delete the empty folders in the 'a' folder
move : The classic 'cut' operation
eg : move c:\a c:\b -> Moves the folder'a' to folder 'b' in the c: direc
tory.
net : Network troubleshooting commands
user : To create,delete and password setting of a user account
/add : To add new user
eg : net user a a /add -> adds a new user with name 'a' and pass
word 'a'
To change the password for the user 'owner' : type "net user owner *"
It will ask for the new password and you will have to confirm it.
/delete : to delete a user :: net user owner /delete :: To delete the us
er owner
/times : to specify the time allowed for the user to logon : Times she
n he could logon eg : net user a /times:all
here the 'all' parameter sees to it that the user 'a' can log
on at all times by default if /times is not given any value then
it will not be able to logon at any time
To view all user related information just type "net user owner" -> to get info
on the user 'owner'
localgroup : It can be used to give a user administrator privileges you
can put a user into any of the user groups
eg: net localgroup administrator owner /add -> to add owner user
into administrator group
You can view the different groups available by just typing "net localgro
up"
/comment :To give comment to the particular user you have created
eg:net localgroup owner /add /comment:"Owner"
net localgroup a /delete : To delete the user 'a' from a localgroup
net view : To view the hostnames of all the computers in the same networ
k
net view /all : To view all hostnames even if offline
net view /cache : To view all the cached files
net time : To get the time fromv a time server
net start : To start a service; eg: net start spooler
ping : Packet Inter Net Gopher :eg : ping 192.1.1.1 : To send icmp signals to th
e specified system : By default windows sends 4 signals - if for each there is a
reply then it means a good connectivity.
-t : Unlimited number of signals are send : It could result in the speci
fied system crashing.
-a : Resolves the IP addresses into corresponding host names
-n : Used to specify the number of packets to be send : eg : ping -n 2 1
92.1.1.1 -> sends 2 packets to the specified machine
-l : To specify the size of the packets : maximum size is 65500 bytes
-f : No fragmenting of the packets
-I : To set the time to leave (ttl)
-v : Used to set the type of service(tos)
-s : Set timestamp for each hops
-j : To ping to list of hostnames in a file: eg:ping -j hostfile.txt 101
.1.1.1
-k : Forces packets to flow to the specified host
-w : To set waiting time for the echo reply
telnet : to connect to a remote host : eg:telnet a - > connects to a system wit
h hostname 'a'
-a:Auto logon to the remote host
-f:Logs all the successful logons and the unsuccessful logons etc
-l:Logons with the local user credentials
-t:Helps to specify the termonal type : like : ansi,vtnt,vt100,vt52
Telnet is usually done into the port 23 but you can also telnet to the p
ort 21 which is the port for ftp by
telnet 101.1.1.1 21
tracert : Trace Route eg : tracert www.google.com
-d : No resolving of ip address
-h : To change the number of hops : maximum : 30 ->by default eg : trace
rt -h 5 www.google.com
-j : To tracert to a list of hostnames in a file eg : tracert -j a.txt
-w : To set delay times in milliseconds
ipconfig : Used to display the details about the mac address,the network connect
ions etc.
/all : Used to display the detailed info of the above stated and more pa
rameters
/release : Used to release the currently assigned ip address
/flushdns : Used to clear the dns resolver cache
/registerdns : Used to re-register the dns
/displaydns : Used to display the dns cache
/showclassid : Displays all the Class IDs that are usable for the curren
t adapter
/setclassid : Used to set the class IDs for the specific adapter
* : Used to set wildcards : eg : ipconfig /release abc* -> releases the
ip with 'abc' as the starting
hostname : Dispalys the name of the host
ftp : To download and upload files ; eg : ftp a.com -> connecting to the rem
ote server of a.com
eg : ftp a@a.com -> where username is 'a'
ftp -a -> implies anonymous login if allowed
dir : displays all the ftp directories
in ftp ; nothing is encrypted even the username and password is tranfere
d as plain text so its better use encrypted versions such as ssh.
pwd : Present Working Directory : Displays the current working directory
get : eg ; get a,txt -> gets the file from the ftp server
send : eg : send a.txt -> uploads the file into the remote server
mget and mput : to get and send multiple files form and into the remote
server respectively
bye : To get out of the ftp prompt
ascii : To set the mode of transfer into ascii mode
binary : To set the mode of transfer into binary mode
delete : To delete a file from the remote server
rmdir : To remove a particular directory from the remote system
-n : Autologin
-i : Deactivate the interactive mode
-s : It takes up a text file and runs the ftp commands in it

You might also like