Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Last active October 23, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmunk/a0e736e4a773677bc75abf9e79ffd2fc to your computer and use it in GitHub Desktop.
Save mmmunk/a0e736e4a773677bc75abf9e79ffd2fc to your computer and use it in GitHub Desktop.
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