User Tools

Site Tools


windows_batch_scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
windows_batch_scripting [2015/07/23 15:15] – add Escape an exclamation mark when EnableDelayedExpansion is active zertrinwindows_batch_scripting [2015/08/04 20:18] (current) – add "Delete folders older than 10 days" zertrin
Line 96: Line 96:
 </code> </code>
 ++++ ++++
 +
 +==== Check if the current batch script has admin rights ====
 +
 +from http://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
 +
 +<code>
 +@echo off
 +goto check_Permissions
 +
 +:check_Permissions
 +    echo Administrative permissions required. Detecting permissions...
 +
 +    net session >nul 2>&1
 +    if %errorLevel% == 0 (
 +        echo Success: Administrative permissions confirmed.
 +    ) else (
 +        echo Failure: Current permissions inadequate.
 +    )
 +
 +    pause >nul
 +</code>
 +
 +
 +==== Get current time in a locale independent way ====
 +
 +from http://serverfault.com/questions/227345/locale-unaware-date-and-time-in-batch-files
 +
 +<code>
 +FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
 +set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
 +</code>
 +
 +
 +==== Delete folders older than 10 days ====
 +
 +from http://stackoverflow.com/questions/5497211/batch-file-to-delete-folders-older-than-10-days-in-windows-7
 +
 +<code>
 +FORFILES /S /D -10 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"
 +</code>
 +
windows_batch_scripting.1437635745.txt.gz · Last modified: by zertrin