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
ERROR_NO_MORE_ITEMS =
259

Instance Method Summary collapse

Methods included from FFI::Library

attach_function_private

Instance Method Details

#delete_key(key, subkey_name, mode = KEY64) ⇒ Object



58
59
60
# File 'lib/puppet/util/windows/registry.rb', line 58

def delete_key(key, subkey_name, mode = KEY64)
  reg_delete_key_ex(key, subkey_name, mode)
end

#delete_value(key, subkey_name) ⇒ Object



83
84
85
# File 'lib/puppet/util/windows/registry.rb', line 83

def delete_value(key, subkey_name)
  reg_delete_value(key, subkey_name)
end

#each_key(key, &block) ⇒ Object

subkey is String which contains name of subkey. wtime is last write time as FILETIME (64-bit integer). (see Registry.wtime2time)



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/puppet/util/windows/registry.rb', line 43

def each_key(key, &block)
  index = 0
  subkey = nil

  subkey_max_len, value_max_len = reg_query_info_key_max_lengths(key)

  begin
    subkey, filetime = reg_enum_key(key, index, subkey_max_len)
    yield subkey, filetime if !subkey.nil?
    index += 1
  end while !subkey.nil?

  index
end

#each_value(key, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/puppet/util/windows/registry.rb', line 68

def each_value(key, &block)
  index = 0
  subkey = nil

  subkey_max_len, value_max_len = reg_query_info_key_max_lengths(key)

  begin
    subkey, type, data = reg_enum_value(key, index, value_max_len)
    yield subkey, type, data if !subkey.nil?
    index += 1
  end while !subkey.nil?

  index
end

#keys(key) ⇒ Object



35
36
37
38
39
# File 'lib/puppet/util/windows/registry.rb', line 35

def keys(key)
  keys = {}
  each_key(key) { |subkey, filetime| keys[subkey] = filetime }
  keys
end

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



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

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 '%{key}\\%{path}'") % { key: hkey.keyname, path: path }, error.code, error)
  end
end

#root(name) ⇒ Object



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

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

#values(key) ⇒ Object



62
63
64
65
66
# File 'lib/puppet/util/windows/registry.rb', line 62

def values(key)
  vals = {}
  each_value(key) { |subkey, type, data| vals[subkey] = data }
  vals
end