Monday 26 March 2018

command line - Batch script: how to check for admin rights


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.



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...