Module: Puppet::Util::Windows::Registry
- Extended by:
- FFI::Library
- 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
- #delete_key(key, subkey_name, mode = KEY64) ⇒ Object
- #delete_value(key, subkey_name) ⇒ Object
-
#each_key(key, &block) ⇒ Object
subkey is String which contains name of subkey.
- #each_value(key, &block) ⇒ Object
- #keys(key) ⇒ Object
- #open(name, path, mode = KEY_READ | KEY64, &block) ⇒ Object
- #root(name) ⇒ Object
- #values(key) ⇒ Object
-
#values_by_name(key, names) ⇒ Hashtable<String, Object>
Retrieve a set of values from a registry key given their names Value names listed but not found in the registry will not be added to the resultant Hashtable.
Methods included from FFI::Library
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
105 106 107 |
# File 'lib/puppet/util/windows/registry.rb', line 105 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, _ = 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/puppet/util/windows/registry.rb', line 90 def each_value(key, &block) index = 0 subkey = nil _, 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 |
#values_by_name(key, names) ⇒ Hashtable<String, Object>
Retrieve a set of values from a registry key given their names Value names listed but not found in the registry will not be added to the resultant Hashtable
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppet/util/windows/registry.rb', line 75 def values_by_name(key, names) vals = {} names.each do |name| FFI::Pointer.from_string_to_wide_string(name) do |subkeyname_ptr| begin _, vals[name] = read(key, subkeyname_ptr) rescue Puppet::Util::Windows::Error => e # ignore missing names, but raise other errors raise e unless e.code == Puppet::Util::Windows::Error::ERROR_FILE_NOT_FOUND end end end vals end |