How to create .bat or batch files in Windows

As mentioned earlier, a batch file contains a series of DOS commands and are used to automate the frequently performed tasks. Thus, you don’t have to repeatedly write the same commands. A batch file is created using a Notepad. The text file consists of the commands you want to execute.  To create a Batch file, you have to write the command as text in Notepad, and save the file as a .bat file. To execute a command, you simply need to double-click the batch file. Hence, a well-written batch file in Windows can save a lot of time.

Some basic Commands in Batch Files:

ECHO: To display the text on the screen@ECHO OFF: To hide the textSTART: To run a file with its default applicationREM: To enter a comment line in the programMKDIR: To create directoriesRMDIR: To remove directoriesDEL: To delete filesCOPY: To copy a file or filesXCOPY: To copy files with extra optionsFOR/IN/DO: To specify filesTITLE: To edit the title of the window

Cool and fun batch file tricks

1. Matrix

Remember the movie ‘Matrix’? You can actually make your background resemble that green Matrix screen with this batch file. It is definitely for the cool look and nothing else. To create this kind of batch files in Windows, follow these steps: Step 1: Open a Text Document and rename it as “matrix.bat”. As soon as the text file’s extension is changed to .bat, its icon changes to a gear.

Step 2: Now you can edit the file to write your program. For this, right-click on the file and click on ‘Edit’. It should open in notepad. Here are the command lines that you need to paste on the notepad. @echo off color 2 :start echo %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% goto start Click on ‘Save’ and double-click on it. It will give the Matrix effect in a window. Maximize the CMD windows and press F11 to get a better full-screen effect.

2. Password Creator

You can even create a password-protected file that is created and accessed using a Batch (.bat) file. This is one of the lightly useful batch files in Windows that should work just fine for hiding things from people with little or no computer or batch file knowledge. Follow these steps to create the Password Creator batch files in Windows: Step 1: Open Notepad Step 2: Copy and paste the following code cls @ECHO OFF title Cyber Attack Weapon System if EXIST “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” goto UNLOCK if NOT EXIST Hidden goto MDHidden :CONFIRM echo Are you sure to lock this folder? (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 echo Invalid choice. goto CONFIRM :LOCK ren Hidden “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” attrib +h +s “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” echo Folder locked goto End :UNLOCK echo Enter password to Unlock Your Secure Folder set/p “pass=>” if NOT %pass%== 1234 goto FAIL goto UNLOCK2 :UNLOCK2 CLS echo Enter password to Unlock Your Secure Folder set/p “pass=>” if NOT %pass%== 1234 goto FAIL attrib -h -s “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” ren “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” Hidden echo Folder Unlocked successfully goto End :Fail @echo off color 02 echo Warning-Virus Initiated total hardrive corruption imminent timeout /t 5 /nobreak >nul set count= 0 :tricks if %count% == 200 goto shutdown echo %random%%random%%random%%random%%random%%random%%random%%random% set /a count=%count%+1 goto tricks :shutdown cls :shutdown shutdown -s -t 45 /c “You have tried to acces a file that is not yours.Good-Bye.” echo Enter password Start Abort Sequence set/p “pass=>” if NOT %pass%== 1234 goto shutdown echo Abort Inittiated goto Abort :Abort C:\Windows\System32\shutdown.exe -a Abort Successful timeout /t 3 /nobreak >nul CLS goto unlock goto end :MDHidden md Hidden echo Hidden created successfully Step 3: Set the password The passwords are set by default to 1234. They can also be changed. To change the password, find in the code where it says: if NOT %pass%== 1234 goto And replace 1234 with your password of choice. Save the file with .bat extension. When you open the file for the first time, it will flash, and another file will appear named “Hidden”. To hide this file, simply click the original file again and it will ask you if you want to hide the file.  If you type Y, then it hides it, but if you type N, nothing happens. After you hide it and later want to access it, you need to click the original file again, and it will prompt you for a password. However, you need to remember that the method is not foolproof. Anyone with little knowledge or experience in computer systems and Batch files will most likely be able to circumvent it rather quickly.

3. Color Tester

If you want to try color testing using the batch files in Windows, then here is a code for it. It’s simple, and it can be pretty useful. Open a notepad and copy-paste the following code. @echo off:testhelp colorecho ———————————————————-echo.echo Type a color code to test colors.echo To exit, just press the X.set/p color=color %color%goto test Save the files with an extension of .bat. If you want to know more about such Batch file tricks in Windows, you may visit Instructable.com.