windows batch file code example

Example 1: bat stop if call command fails

The ERRORLEVEL environment variable holds the latest return value:
IF %ERRORLEVEL% NEQ 0 (
  echo "Previous command execution failed."
  exit %ERRORLEVEL%
)

Example 2: batch file cmd command

c:\
cd c:\Program files\IIS Express
start iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
start http://localhost:8088/default.aspx
pause

Example 3: batch windows for

syntax-FOR-List of numbers   
       FOR /L %%parameter IN (start,step,end) DO command 
   
syntax-FOR-Command Results 
       FOR /F ["options"] %%parameter IN ('command to process') DO command

Example 4: what is a windows batch file

@ECHO OFF
ECHO Congratulations! Your first batch file executed successfully.
PAUSE

Tags:

Misc Example