.bat or .cmd files

shivam99aa

Disciple
i have seen persons making .bat or .cmd files and doing tricks with them on computer.i too have done a lot of them but what i wanted to know is there any language in which they are written,if not(which should not be as i think) then what syntax they follow and how can one can get command on them.
 
^^What exactly do you want to create a .bat / .cmd file for ?? .bat files usually accept DOS commands.
I had once made a .bat file to do a simple copy of multiple files to one file in binary mode and once made a file to connect to a FTP server using a hardcoded id and password and GETting a file from a predefined unix directory.
 
what i want to know is how to make these files on my choice to do specific tasks and if they accept DOS commands then can you tell me the place to learn them as what i understand from looking into these files is that they are very useful in nature if properly used so i want to learn every bit about them.
 
AFAIK bat and cmd files types are collection of dos commands written so that they can execute without any intervention

here is a sample of a bat locker file

Code:
cls 
@ECHO OFF 
title A small locker for Portable Drive...by CA50
REM /Coded by ~CA~. Don`t modify else BOOM!!!/
REM /Last coding done on 11:10 PM 18 April 2011/
if NOT EXIST autorun.inf md autorun.inf
attrib +r +s +h +a autorun.inf
color ac 
if EXIST "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" goto UNLOCK 
if NOT EXIST Locker goto MDLocker 
:CONFIRM
echo.                                                                                          
echo                        .##.  .*###.*.    .########                       
echo                     .*##*  *########    .##***#####                      
echo                    *###..####  #..      ..    .####*                     
echo                   *###. .####  #         #####**####.                    
echo                  *####   ####  #        #*.*##  *####                    
echo     .####*. .##  #####   ####  #.      ..   *.   *###*       .####*. .##.
echo    *###########  #####   ####  #.          .#****#####.     *########### 
echo    *#    .***.   *####*  ####  #.         .############     .#.   .*#*.  
echo                   #####. **.   #  .#*     #.       #####                 
echo                    ######.     ####*  .######**     #####*.              
echo                     .############*   *########      .####*               
echo                        .*####**      *.    **         **.                 
echo.
echo.                                                                                                                                                                                                                             
echo Do you want to lock this Locker??
echo Your response : (Y/N) 
set/p "cho=>" 
if %cho%==Y goto LOCK 
if %cho%==y goto LOCK
if %cho%==n goto END 
if %cho%==N goto END
color C
echo.
echo ***************************     INVALID CHOICE     ****************************
echo *********************** contact : [email]mail2ca99@gmail.com[/email] ************************* 
echo.
pause. 
goto END 
:LOCK 
ren Locker "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" 
attrib +h +s +r +a "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
echo Status : Locked
goto End 
:UNLOCK
color ca 
echo.                                                                                          
echo                        .##.  .*###.*.    .########                       
echo                     .*##*  *########    .##***#####                      
echo                    *###..####  #..      ..    .####*                     
echo                   *###. .####  #         #####**####.                    
echo                  *####   ####  #        #*.*##  *####                    
echo     .####*. .##  #####   ####  #.      ..   *.   *###*       .####*. .##.
echo    *###########  #####   ####  #.          .#****#####.     *########### 
echo    *#    .***.   *####*  ####  #.         .############     .#.   .*#*.  
echo                   #####. **.   #  .#*     #.       #####                 
echo                    ######.     ####*  .######**     #####*.              
echo                     .############*   *########      .####*               
echo                        .*####**      *.    **         **.                 
echo.
echo.                                                                          
echo Enter password for unlocking "Locker"
set/p "pass=>" 
if NOT %pass%== password goto FAIL 
attrib -h -s -r -a "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" 
ren "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Locker
echo Status : Unlocked
goto end 
:FAIL
color C
echo.
echo.
echo **************************    INVALID PASSWORD     ***************************
echo *********************** contact : [email]mail2ca99@gmail.com[/email] ************************ 
echo.
pause
goto end 
:MDLocker 
md Locker 
echo Locker program successfully executed
goto End 
:End
To use this just copy and save this code as <any_name>.bat
and the default password is "password"


--- Updated Post - Automerged ---

You can refer this Batch file - Wikipedia, the free encyclopedia
 
Ok here is a small explanation

cls clears screen
@ECHO OFF The echo command writes character strings to standard output
title A small locker for Portable Drive...by CA50 title that should be displayed
REM /Coded by ~CA~. Don`t modify else BOOM!!!/ just info about the code, these steps are skipped while execution
REM /Last coding done on 11:10 PM 18 April 2011/
if NOT EXIST autorun.inf md autorun.inf creates a autorun folder if it doesn't exit, as a precaution against autorun virus
attrib +r +s +h +a autorun.inf changes attribute of the directory to hidden,read only and marks it as a system directory
color ac for changing color of the DOS console
if EXIST "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" goto UNLOCK check if there is a locked folder, if yes then it jumps to unlock part
if NOT EXIST Locker goto MDLocker when no locked folder is found, then it jumps to MDlocker
:CONFIRM label
echo.
echo .##. .*###.*. .######## UI
echo .*##* *######## .##***##### UI
echo *###..#### #.. .. .####* UI
echo *###. .#### # #####**####. UI
echo *#### #### # #*.*## *#### UI
echo .####*. .## ##### #### #. .. *. *###* .####*. .##.UI
echo *########### ##### #### #. .#****#####. *########### UI
echo *# .***. *####* #### #. .############ .#. .*#*. UI
echo #####. **. # .#* #. ##### UI
echo ######. ####* .######** #####*. UI
echo .############* *######## .####* UI
echo .*####** *. ** **. UI
echo.UI

echo Do you want to lock this Locker?? user prompt
echo Your response : (Y/N) user prompt
set/p "cho=>" accepts user choice
if %cho%==Y goto LOCK matches user data for Yes or No
if %cho%==y goto LOCK matches user data for Yes or No
if %cho%==n goto END matches user data for Yes or No
if %cho%==N goto END matches user data for Yes or No
color Cfor changing color of the DOS console
echo.UI
echo *************************** INVALID CHOICE ****************************UI
echo *********************** contact : email ************************* UI
echo.UI
pause. pause execution
goto END jumps to END as the user have pressed invalid key
:LOCK label
ren Locker "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" renames the locker directory to My Computer with its address, so that the locker folder changes to My computer
attrib +h +s +r +a "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" changes the attributes
echo Status : Locked UI
goto End jumps to END
:UNLOCKlabel
color ca for changing color of the DOS console
echo.
echo .##. .*###.*. .######## UI
echo .*##* *######## .##***##### UI
echo *###..#### #.. .. .####* UI
echo *###. .#### # #####**####. UI
echo *#### #### # #*.*## *#### UI
echo .####*. .## ##### #### #. .. *. *###* .####*. .##.UI
echo *########### ##### #### #. .#****#####. *########### UI
echo *# .***. *####* #### #. .############ .#. .*#*. UI
echo #####. **. # .#* #. ##### UI
echo ######. ####* .######** #####*. UI
echo .############* *######## .####* UI
echo .*####** *. ** **. UI
echo.UI
echo Enter password for unlocking "Locker" password prompt
set/p "pass=>" accepts user password
if NOT %pass%== password goto FAIL matches password with default password, if wrong then jumps to FAIL
attrib -h -s -r -a "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" restores changed attributes
ren "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Locker renames My computer to Locker
echo Status : UnlockedUI
goto end jumps to END
:FAILlabel
color C for changing color of the DOS console
echo.UI
echo.UI
echo ************************** INVALID PASSWORD ***************************UI
echo *********************** contact :email ************************ UI
echo.UI
pause pause execution
goto end label
:MDLocker
md Locker creates a new directory named - Locker
echo Locker program successfully executedUI
goto End jumps to end
:Endexecution ends
i hope this is clear
 
i got it and really works and was nice i can lock any of my data and no body is going to think of this but what i want to ask from you is that how do you learn to do all this as i want to write these programs on my wish
 
shivam99aa said:
i got it and really works and was nice i can lock any of my data and no body is going to think of this but what i want to ask from you is that how do you learn to do all this as i want to write these programs on my wish
there is no magic pill to do this in an instant. Practicing a lot is the only way. Start with the basics of scripting. Try chaining multiple commands, reading input from user, using iterations etc.

Google is more than enough for you to start learning this. Make up a problem which you want to solve and find the solution yourself. If you are having trouble finding answers, ask more questions, even stupid ones. Someone will point you in the right direction.
 
i know there is no magic pill and i even dont want it and what you sugest me i have started it before but i think there is certain criteria to do these things but since i know what to do more clearly i will try more and hope on a day i will do things on wish.thanks a lot to you guys for your help.
 
Back
Top