How To Make A Batch File: A BATCH FILE is nothing but a text file that contains a series of batch or dos commands which can be executed sequentially and in the Desired order.
A batch file is created to reduce time by executing the same commands Which are used to run frequently?
To create one of these files you don’t need special programming skills just some basic understanding of MS-DOS and dos commands.
A Batch file has an extension. BAT and any primary name or first name of your choice. To run a batch file you just need to type the primary name of a file in dos prompt
for Example:: I have created a batch file name abc.bat to run this I will type abc in the dos prompt and will Press Enter.
Autoexec.bat is a prime example of a batch file that was used in earlier windows and ms-dos it would have necessary boot files which used to load every time the computer booted.
How to Write a Batch File?
Step No 1::
Go to Start —-> Run— >Cmd
Step No 2::
Type the following Dos Commands to create a Batch file
- c:\>copy con abc.bat (Press Enter)
- copy con
- del pa.exe
- PRESS CTRL+Z OR F6 To save the file
Now To run this .bat file just type abc in the command windows without the extension.
The command which I have included in the .bat file will be executed sequentially which means the dir command will be executed first then dir/p/w then copy con so all these commands will be executed in order.
Create .Bat file using Notepad
Step No 1::
Go to start—> Run —>Type Notepad
Step No 2::
Type the following command.
Just save the file with a .bat extension shown in the image below.
Command Used In Batch file
- ECHO:: This command is used to print text on the display unit. Anything written after echo is displayed on the screen.
- ECHO OFF:: Echo off is written before starting a bat file this tells the program don’t show the command while executing the code.
- CLS:: This command clears the screen of previous outputs.
- CALL:: This command is used to run another batch script within a batch file. If the batch file which is called does not exist it will display an error message.
- EXIT:: This command is used to exit from dos windows.
- IF:: it is used to check certain conditions. if the condition exists or comes out to be true it will perform the given instruction.
- REM:: It allows us to add comments or remarks between the codes and this remark is not displayed while the batch file is executed.
- GOTO:: It is used to go to LABEL.
- PAUSE:: Prompts the user to “Press any key to continue”.
- IPCONFIG:: – output a lot of network information in the dos screen.
- PING:: – Pings an IP, let us know whether you are able to contact the requested IP.
People Are Also Reading
How to create a batch file acting like a virus?
Here we are going to see how to create a batch file that will open itself numerous amount of times and will presume to be a virus but let me tell you its harmless and this is just an example of how to write a .bat file
Let's start doing it
- Step No 1::
- Go to –> start — > Run
- Step No 2:: type cmd
- Step No 3:: now as you can see your command prompt has been opened just type the following code and run the file which will be named virus.bat.
- C:\>copy con virus.bat
- Echo on (Press Enter)
- Start virus.bat (Press Enter)
- Echo off (Press Enter)
- CTRL+Z OR F6 to save the file
Now note we have just created a bat file name virus.bat in c drive. go to c drive and double-click on the virus.bat we just created.
Batch Script which will delete all files in a folder?
- STEP 1:: Click Start
- STEP 2:: Click Run
- STEP 3:: TYPE ….cmd
Consider u have a folder name songs in D drive you have to delete all files present in that folder… *Caution::: The Content of the website is only for Education purposes…Viewers are requested to execute the commands on their personal responsibility …chtips.com will not be liable for any damage….:
Type the following command
- c:\> copy con virus.bat (Press Enter)
- cd songs (Press Enter)
- del/q *.* (Press Enter)
- ctrl +z (Press Enter)
Now go to c drive a double click on the file name virus.bat..you will be amazed to see all the files in the songs folder has been deleted.