How to determine a batch file is running as administrator

J.D.CHEN

New Member
Hi

How to determine whether a batch file (*.cmd) is running as an administrator?

In the cmd script, I want to add a sentence to determine whether it is running as an administrator, according to the judge to take a different approach.

(Sorry, my English is not good...)

Now my approach is:
--------------------------------------------------
set ADMINTEST=%SystemRoot%\$ADMIN_TEST_JDCHEN
copy "%~f0" "%ADMINTEST%" > nul
:: 返回值 0=true, 1=false
if not errorlevel 1 (
del "%ADMINTEST%" > nul
echo Running As Administrator.
) else echo Acquire Administrative Privileges.
---------------------------------------------

perhaps there is a better practice?
 
Last edited:

My Computer

Back
Top