Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I check if the current batch script has admin rights?

I know how to make it call itself with runas but not how to check for admin rights. The only solutions I've seen are crude hack jobs.

share|improve this question
    
@Bobby: That was asking how to do it in bash though. – paradroid Oct 29 '10 at 12:56
1  
@Jason404: Wtf?! How the hack did I misread Batch for Bash? oO' @Tilka: My sincere apologies. – Bobby Oct 29 '10 at 13:04
up vote 4 down vote accepted

You could always do something like this

mkdir "%windir%\system32\test" 2>nul
if "%errorlevel%" == "0" (rmdir "%windir%\system32\test" & echo Is admin) else (echo Not an Admin)

Not the best of ways but works for me all the time.

share|improve this answer
    
This is a hack job which the OP is trying to avoid............. – Pacerier Feb 3 '15 at 10:46

This is the best kludge I could think of, using standard commands:

net user %username% | findstr /r Administrator.
if %errorlevel% == 1 (
echo This is not an admin account
) else (
echo This is an admin account
)
share|improve this answer
    
That doesn't work when you are in a domain. And when I tried "net user %username% /domain" the Local Group Membership section didn't contain any groups although I have local admin rights. Strange... – flacs Oct 29 '10 at 13:19
1  
Plus the output is localized. – flacs Oct 29 '10 at 13:22
1  
Besides, one can run a batch file without administrator rights from an account who is in Administrators group (this especially relates Vista/7). – utapyngo Nov 9 '11 at 4:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .