Skip navigation

What commands can I use in a batch file?

A. Windows NT 4.0 introduced several extensions to cmd.exe. Use these extensions to ensure that the HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions registry entry is set to 1.

Related: What commands can be used to configure the command window?

The following table lists the most commonly used commands.

call <batch file> Calls one batch file from inside another. The current batch file’s execution is suspended until the called batch file completes.
exit Stops a batch file from running. If one batch file calls another, exit stops both batch files.
findstr <string> <filename(s)> Finds a string in a file. This powerful command has several parameters.
for Standard for loop. The command
for /L %n IN (1,1,10) DO @ECHO %n
Would print 1 to 10.
goto <label> Causes a program’s execution to skip to a given point. A colon must precede the label name. For example,
goto label1<br>
...<br>
:label1<br>
...
if <condition> .. The if statement has a lot of functionality. Common uses include the following.
if /i &lt;string1&gt; &lt;compare&gt; &lt;string2&gt; &lt;command&gt;
The /i parameter makes the comparison case-insensitive. The comparison can be one of the following.
EQU—equal
NEQ—not equal
LSS—less than
LEQ—less than or equal
GTR—greater than
GEQ—greater than or equal
if errorlevel<br>
if exist &lt;file name&gt;
rem <string> A comment.
start <window title> <command> Starts a new command session and runs a given command. Unlike with the call command, the current batch file’s execution continues.

Learn more: Resource Kit Batch File Commands

The Microsoft Windows NT Resource Kit includes some additional utilities that you might find useful.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish