Class: Reg

Inherits:
Object show all
Defined in:
lib/pik/windows_env.rb

Instance Method Summary collapse

Constructor Details

#initialize(user = User.new) ⇒ Reg

Returns a new instance of Reg.



49
50
51
# File 'lib/pik/windows_env.rb', line 49

def initialize(user=User.new)
  @user = user
end

Instance Method Details

#hkcr(subkey, name = '') ⇒ Object



67
68
69
# File 'lib/pik/windows_env.rb', line 67

def hkcr(subkey,name='')
  open(:HKEY_CLASSES_ROOT, subkey, name)
end

#hkcu(subkey, name = '') ⇒ Object



63
64
65
# File 'lib/pik/windows_env.rb', line 63

def hkcu(subkey,name='')
  open(:HKEY_CURRENT_USER, subkey, name)
end

#hklm(subkey, name = '') ⇒ Object



59
60
61
# File 'lib/pik/windows_env.rb', line 59

def hklm(subkey, name='')
  open(:HKEY_LOCAL_MACHINE, subkey, name)
end

#install_hkey(subkey, name = '') ⇒ Object

reads the registry hive that the installer would write to based on user rights



55
56
57
# File 'lib/pik/windows_env.rb', line 55

def install_hkey(subkey, name='')
  @user.admin? ? hklm(subkey,name) : hkcu(subkey,name)
end

#open(key, subkey, name) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/pik/windows_env.rb', line 71

def open(key, subkey, name)
  key = Win32::Registry.const_get(key)

  key.open(subkey) do |reg|
    reg_typ, reg_val = reg.read(name) rescue nil
    return reg_val
  end
end