Platinum Partner

Cross-platform detection if running as root/Administrator

Detects if the current running Ruby process is running with Administrative privledges / root.  This works on Linux/Unix, Windows, and JRuby.

is_windows logic came from Puppet.  The registry trick came from Stackoverflow .

Sorry for the bad formatting.  The dzone widget isn't cooperating with me.

require 'rbconfig'

def is_root?
  if RbConfig::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i
    require 'win32/registry'
    
    begin
      Win32::Registry::HKEY_USERS.open('S-1-5-19') {|reg| }
      true
    rescue
      false
    end
  else
    (ENV['USER'] == 'root')
  end
end
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}