Skip to content

Instantly share code, notes, and snippets.

@charlesroper
Created February 17, 2009 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save charlesroper/65931 to your computer and use it in GitHub Desktop.
Save charlesroper/65931 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 as part of the local Administrators group in WinXP.
#
# 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