/build/static/layout/Breadcrumb_cap_w.png

Check for elevated admin rights in batch file

Just a few lines of code in a batch file will check if the batch file is executed with full administrator rights. This is great in eg. Win7 enviroments and when used with superusers who tends to forget :)

 

@ECHO OFF

::Admin check
AT > NUL
IF %ERRORLEVEL% EQU 0 (
    GOTO execute
) ELSE (
    ECHO Script must run as admin, exiting...
    Pause
    EXIT /B 1
)

::Script below

:execute


Comments

  • Nice tip! - mikergray 12 years ago
  • With my company starting the win7 migration adding this code in will help me make sure the script is being executed with full admin rights thanks for the post - shigbee 11 years ago
  • Thanks for the tip, I have the desktop guys try to use my installs and call me when they forget to log a user out and use admin rights this should stop those calls! - GAKIS 11 years ago
  • Thank you for this tip here, I can now implement several of my batch files with ease! - JakeTheITSnake 8 years ago
  • I would not recommend using a deprecated executable in that way. Instead, use whoami.exe /groups and look for S-1-16-12288 and S-1-16-16384. - cogx 8 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ