Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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... –  Tilka Oct 29 '10 at 13:19
1  
Plus the output is localized. –  Tilka 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.