Kush's Blog

Kush's Blog

What is a Batch File ?

What is a Batch File ?

Batch files are plain text files with a bunch of commands in them for the command line interpreter to execute. You may also hear a batch file referred to as a script file. It’s important to remember that batch files are strictly Windows-based. Linux and other operating systems has their own version of the batch file for executing script commands, but “batch” is specifically for Windows.

batch2.JPG

Batch files are plain text files that contain commands or instructions for the command line interpreter to execute. In this case, since a batch file can only be operated within the Windows operating system, that interpreter or “shell program” would be cmd.exe, which you might recognize more as Command Prompt.

The shell program takes batch files and executes whatever instructions are inside. These instructions inside batch files can be a bunch of different commands, but many people primarily use batch files to automate repetitive tasks.

On the malicious side of things, people can use batch files/scripts to harm your computer. Using a batch file, you can easily plant malware on your computer, delete imperative files, crash the PC and so on.

So while batch files are used for a lot of good — such as automating repetitive tasks — they can be used to harm as well. That said, it’s good practice to not just run any batch file you come across. You can (usually) see the contents of a batch file by right-clicking on it and selecting Open with Notepad or your preferred plain-text editor.

batch1.JPG

What are the modes in the batch ?

These are divided into two types of batch modes.

  • Interactive mode. In this mode human interaction is needed to perform the task after execution for the file. Basing on the human input operations are going to be done. This is like program asking for do you really want to delete any file or asking how many times you want a particular thing to be done.

  • Batch mode (silent mode). This mode is completely opposite to interactive mode. After execution of the batch file everything will be done silent in the background. There is no need of human interaction in this mode. No need no inputs or instructions for our side.

Type of batch commands

  • internal commands. Internal commands are those which come by default with operating systems in other words we call them as built-in commands. For example, dir, cls, echo, del and many more.

  • external commands. External commands resemblance the command often created after installing any applications. Mostly some external commands will only work in run box. For example: PsExec, PsFile, PsGetSid, PsInfo, PsKill, PsList, PsLoggedOn and so on.

"cd" —- change director.

“: and goto” —- for loop implication.

“echo” —- print.

“echo off” —- stop printing the execution of batch file.

“call” —- used for triggering or calling the file and commands.

“start” —- to start application and services.

“net users” —- Adds or modifies user accounts, or displays user account information

“%random%” —- environmental variable

“net stop” —- used for stopping services of user accounts

“reg add” —- adding content to register editor

“ping” —- sending packets over network to find host alive or dead

Interested in reading more such articles from Kushagra Sharma?

Support the author by donating an amount of your choice.