Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tips & Tricks for Windows Batch files
REM This file is not meant to be run in it's entirety
REM --- Check if script is run as administrator
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script must be run with administrator privileges
pause
exit /B
)
REM --- Output multiple commands (stdout and stderr) to log file
(
echo Hello
date /T
net stop service1
xcopy src dst /V /F /H /Y
) >>Log.txt 2>&1
REM --- Manipulating services
REM Does not wait:
sc stop service2
REM Does wait:
net stop service3
REM --- Get a user input string
set /P VAR1="Prompt for variable 1: "
echo %VAR1%
REM --- Wait 5 seconds
timeout /T 5 /NOBREAK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.