Last active
October 23, 2019 09:44
-
-
Save mmmunk/a0e736e4a773677bc75abf9e79ffd2fc to your computer and use it in GitHub Desktop.
Tips & Tricks for Windows Batch files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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