Skip to main content

Batch File example to ensure the current user has elevated or administrator privileges to execute the specified commands.

@echo off

:: Make sure the script is running as admin
call :ensure_admin

echo User has admin permissions
exit 0

    if not [%1] == [] echo %~1
    exit 1

    :: 'net session' is just a commmand that is present on all supported
    :: Windows versions, requires admin privileges and has no side effects, see:
    net session >nul 2>&1
    if errorlevel 1 (
        echo This batch script requires administrator privileges. Right-click on
        echo %~n0 and select "Run as administrator".
        call :die "Exiting."
    goto :eof