What are Batch files in Windows? Fun and cool Batch files tricks

 

Batch files in Windows are the script files. A batch file is an unformatted text file. This file consists of a series of commands and has a .bat or .cmd file name extension. The term “batch” is adapted from batch processing – which means non-interactive execution. With batch files in Windows, users can simplify repetitive or routine tasks. When users type the file name at the command prompt, cmd.exe runs the commands sequentially, as they appear in the file. Some typical commands used in the batch files in Windows are – Call, Echo, Endlocal, For, Goto, If, Pause, Rem, Setlocal, and Shift.

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 text
  • START: To run a file with its default application
  • REM: To enter a comment line in the program
  • MKDIR: To create directories
  • RMDIR: To remove directories
  • DEL: To delete files
  • COPY: To copy a file or files
  • XCOPY: To copy files with extra options
  • FOR/IN/DO: To specify files
  • TITLE: To edit the title of the window

Cool and fun batch file tricks

1. Matrix

what-are-batch-files-in-windows-1-7648224

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.

creating-the-matrix-effect-with-batch-file-in-windows-4320486

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 a 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:WindowsSystem32shutdown.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 fool proof. 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

fun-and-cool-batch-files-tricks-7975731

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
:test
help color
echo ----------------------------------------------------------
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.

Source