Beginner's Guide to Windows Batch Scripting
This guide explains common commands used in Windows batch (.bat) scripts, with simple
examples.
------------------------------------------------------------
1. ECHO
Usage: echo Hello
- Displays text in the command window.
- Special: echo. adds a blank line.
- echo off hides command lines from displaying during execution.
- @echo off also hides the command itself.
2. SET
Usage: set name=value
- Stores a variable in the script.
Example:
 set logFile=C:\Users\User\Desktop\log.txt
3. REM or :: (Comments)
Usage: rem This is a comment
- Used to write notes that don't run.
4. IF
Usage: if EXIST "file.txt" echo Found it!
- Conditional logic, based on file existence or variable value.
5. GOTO
Usage: goto start
- Moves script execution to a label like :start
6. PAUSE
Usage: pause
- Freezes script and shows: Press any key to continue...
7. TIMEOUT
Usage: timeout /t 10
- Waits 10 seconds before continuing.
8. SHUTDOWN
Usage: shutdown /s /t 60
- Schedules PC shutdown in 60 seconds.
- /s = shutdown, /r = restart, /t = time delay
9. START
Usage: start notepad.exe
- Opens a program or file.
10. FINDSTR
Usage: findstr "word" file.txt
- Searches for text inside a file (used to extract SFC results).
11. REDIRECTION
> = overwrite output file
>> = append to output file
Example:
 echo Done > log.txt (overwrites)
 echo Done >> log.txt (adds to end)
12. EXIT
Usage: exit
- Closes the script.
------------------------------------------------------------
TIP: Save batch scripts with the .bat or .cmd file extension and run them as administrator when
needed.