-
-
Save klauern/154687 to your computer and use it in GitHub Desktop.
Method to detect whether we are running from an elevated command-prompt under Vista/Win7 or Administrator in WinXP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Method to detect whether we are running from an elevated command-prompt | |
# under Vista/Win7 or as part of the local Administrators group in WinXP. | |
# | |
def elevated? | |
whoami = `whoami /groups` rescue nil | |
if whoami =~ /S-1-16-12288/ | |
true | |
else | |
admin = `net localgroup administrators | find "%USERNAME%"` rescue "" | |
if admin.empty? | |
false | |
else | |
true | |
end | |
end | |
end | |
# | |
# A more terse version of the same thing. | |
# | |
def elevated? | |
whoami = `whoami /groups` rescue nil | |
if whoami =~ /S-1-16-12288/ | |
true | |
else | |
admin = `net localgroup administrators | find "%USERNAME%"` rescue "" | |
admin.empty? ? false : true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment