Skip to content

Instantly share code, notes, and snippets.

@Eibwen
Last active February 18, 2016 16:51
Show Gist options
  • Save Eibwen/33203a807dba118a41f1 to your computer and use it in GitHub Desktop.
Save Eibwen/33203a807dba118a41f1 to your computer and use it in GitHub Desktop.
Useful windows batch file snippets
:: Check if argument equals string
if /i "%1" equ "/resume" (
echo Resuming now!
)
:: Allow argument, but override if needed
set action=%1
if "%action%"=="" (
set action=start
)
:: Check for administrator permissions
NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
ECHO Failure: Current permissions inadequate. You should run this with elevated permissions.
:: `setx` failed without admin permissions
:: Part of `choco install netfx-4.6.1-devpack` failed
goto :eof
)
:: Build a datetime string (20161802T104304)... can't do UTC probably
for /f "tokens=1-8 delims=::./ " %%A in ('echo %DATE% %TIME%') do set FileDateTime=%%D%%C%%BT%%E%%F%%G
:: Better to read: 2016-18-02 104759
for /f "tokens=1-8 delims=::./ " %%A in ('echo %DATE% %TIME%') do set FileDateTime=%%D-%%C-%%B %%E%%F%%G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment