0

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
09stephenb
  • 9,358
  • 15
  • 53
  • 91

2 Answers2

1

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
Community
  • 1
  • 1
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98
1

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
user93353
  • 13,733
  • 8
  • 60
  • 122