Showing posts with label batch-windows. Show all posts
Showing posts with label batch-windows. Show all posts

Tuesday, March 22, 2016

Am I running as Administrator in a Windows batch file

Am I running as Administrator in a Windows batch file

This is a great way to test:

whoami /groups | findstr /b BUILTIN\Administrators | findstr /c:"Enabled group" && GOTO RunningAsAdmin
ECHO This must be run as AdministratorGOTO NotRunningAsAdmin
:RunningAsAdmin


Wednesday, February 24, 2016

Windows Command line redirect stdout and stderr to the same file

I keep forgetting how to do this, so:
Windows Command line redirect stdout and stderr to the same file like this:

someprog.exe > log.txt 2>&1

Friday, September 18, 2015

Don't let environment values persist after a batch file runs

To prevent environment variables declared in a batch from being persisted after the batch file is run, use this command before setting them:

setlocal

Reference: http://ss64.com/nt/setlocal.html