0% found this document useful (0 votes)
6 views4 pages

Batch Scripting Expanded Guide

This document is a beginner's guide to Windows batch scripting, detailing essential commands such as ECHO, SET, IF, and SHUTDOWN with practical examples. It also includes a sample script demonstrating a system check and shutdown process. Additional tips for creating and testing batch files are provided to enhance user experience.

Uploaded by

ytmvlogs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Batch Scripting Expanded Guide

This document is a beginner's guide to Windows batch scripting, detailing essential commands such as ECHO, SET, IF, and SHUTDOWN with practical examples. It also includes a sample script demonstrating a system check and shutdown process. Additional tips for creating and testing batch files are provided to enhance user experience.

Uploaded by

ytmvlogs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Beginner's Guide to Windows Batch Scripting (Expanded Edition)

This guide explains essential Windows batch (.bat) commands and gives practical examples.

------------------------------------------------------------

1. ECHO

Usage: echo Hello

- Prints text to the screen.

Example:

echo Welcome to my script!

echo.

echo Starting system check...

2. SET

Usage: set name=value

- Stores a variable.

Example:

set logFile=C:\Users\User\Desktop\log.txt

echo Log will be saved to %logFile%

3. REM or :: (Comments)

Usage: rem Notes here or :: Notes here

- Adds internal notes or disables lines.

Example:

rem This script checks for updates


4. IF

Usage: if EXIST "file.txt" echo Found file!

- Runs a command only if a condition is met.

Example:

if EXIST "log.txt" del log.txt

5. GOTO

Usage: goto label

- Jumps to a label in the script.

Example:

goto start

:start

echo Running process...

6. PAUSE

Usage: pause

- Freezes script until user presses a key.

Example:

pause

7. TIMEOUT

Usage: timeout /t 10 /nobreak

- Waits before continuing.

Example:

echo Waiting 5 seconds...


timeout /t 5

8. SHUTDOWN

Usage: shutdown /s /t 60

- Schedules system shutdown.

Examples:

shutdown /s /t 0 (shutdown now)

shutdown /r /t 30 (restart in 30s)

9. START

Usage: start [program or file]

Examples:

start notepad.exe

start https://google.com

10. FINDSTR

Usage: findstr "text" filename.txt

Example:

findstr /c:"[SR]" C:\Windows\Logs\CBS\CBS.log > sfc_results.txt

11. REDIRECTION

- > overwrites file, >> appends to file.

Examples:

echo Start > output.txt

echo More >> output.txt

12. EXIT
Usage: exit

- Ends the batch file.

------------------------------------------------------------

BONUS: Sample Script

@echo off

echo Running System Check...

sfc /scannow >> %userprofile%\Desktop\scan_log.txt

echo Done. PC will shut down.

shutdown /s /t 60

------------------------------------------------------------

TIPS:

- Always test scripts in a safe environment.

- Use Notepad to create .bat files.

- Right-click > Run as Administrator when needed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy