문제

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
도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top