Module: Puppet::Util::Windows::Registry

Extended by:
FFI::Library
Included in:
Provider::Package::Windows::Package, Provider::Package::Windows::Package
Defined in:
lib/puppet/util/windows.rb,
lib/puppet/util/windows/registry.rb

Constant Summary collapse

KEY64 =
0x100
KEY32 =
0x200
KEY_READ =
0x20019
KEY_WRITE =
0x20006
KEY_ALL_ACCESS =
0x2003f

Instance Method Summary collapse

Methods included from FFI::Library

attach_function_private

Instance Method Details

#open(name, path, mode = KEY_READ | KEY64, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet/util/windows/registry.rb', line 22

def open(name, path, mode = KEY_READ | KEY64, &block)
  hkey = root(name)
  begin
    hkey.open(path, mode) do |subkey|
      return yield subkey
    end
  rescue Win32::Registry::Error => error
    raise Puppet::Util::Windows::Error.new("Failed to open registry key '#{hkey.keyname}\\#{path}'", error.code, error)
  end
end

#root(name) ⇒ Object



16
17
18
19
20
# File 'lib/puppet/util/windows/registry.rb', line 16

def root(name)
  Win32::Registry.const_get(name)
rescue NameError
  raise Puppet::Error, "Invalid registry key '#{name}'", $!.backtrace
end

#values(subkey) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/util/windows/registry.rb', line 33

def values(subkey)
  values = {}
  subkey.each_value do |name, type, data|
    case type
    when Win32::Registry::REG_MULTI_SZ
      data.each { |str| force_encoding(str) }
    when Win32::Registry::REG_SZ, Win32::Registry::REG_EXPAND_SZ
      force_encoding(data)
    end
    values[name] = data
  end
  values
end