How to make a batch file tell if it is elevated or not

221 views Asked by At

I need a code in the space below to tell if the batch file is elevated or not. I am making a program so that if it is elevated it does something one way and if it is not it does it the other way. Does anyone know a code I could use.

@echo off




:no
echo no
pause
goto exit
:yes
echo yes
pause
goto exit
:exit
2

There are 2 answers

0
Dark Falcon On BEST ANSWER

I would recommend something based off of this script:

@echo off

NET FILE 1>NUL 2>NUL
IF ERRORLEVEL 1 GOTO no
GOTO yes

:no
echo no
pause
goto exit
:yes
echo yes
pause
goto exit
:exit
1
user93353 On

Run some command which requires elevated privilege & check ERRORLEVEL

@echo off
at > nul

if %ERRORLEVEL% EQU 0  goto elevated

REM do non-elevated stuff
goto end

:elevated
REM do elevated stuff

:end