win32/registry is registry accessor library for Win32 platform. It uses importer to call Win32 Registry APIs.

example

Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\foo') do |reg|
  value = reg['foo']                               # read a value
  value = reg['foo', Win32::Registry::REG_SZ]      # read a value with type
  type, value = reg.read('foo')                    # read a value
  reg['foo'] = 'bar'                               # write a value
  reg['foo', Win32::Registry::REG_SZ] = 'bar'      # write a value with type
  reg.write('foo', Win32::Registry::REG_SZ, 'bar') # write a value

  reg.each_value { |name, type, data| ... }        # Enumerate values
  reg.each_key { |key, wtime| ... }                # Enumerate subkeys

  reg.delete_value(name)                           # Delete a value
  reg.delete_key(name)                             # Delete a subkey
  reg.delete_key(name, true)                       # Delete a subkey recursively
end

Predefined keys

  • HKEY_CLASSES_ROOT

  • HKEY_CURRENT_USER

  • HKEY_LOCAL_MACHINE

  • HKEY_PERFORMANCE_DATA

  • HKEY_CURRENT_CONFIG

  • HKEY_DYN_DATA

    Win32::Registry object whose key is predefined key.

For detail, see the article.

Value types

  • REG_NONE

  • REG_SZ

  • REG_EXPAND_SZ

  • REG_BINARY

  • REG_DWORD

  • REG_DWORD_BIG_ENDIAN

  • REG_LINK

  • REG_MULTI_SZ

  • REG_RESOURCE_LIST

  • REG_FULL_RESOURCE_DESCRIPTOR

  • REG_RESOURCE_REQUIREMENTS_LIST

  • REG_QWORD

For detail, see the article.

Class Methods

Create or open the registry key subkey under key. You can use predefined key HKEY_*. desired and opt is access mask and key option.

If subkey is already exists, key is opened and Registry#created? method will return false.

If block is given, the key reg is yielded and closed automatically after the block exists.

Replace %-enclosed substrings in str into the environment value of what is contained between the %s. This method is used for REG_EXPAND_SZ.

For detail, see ExpandEnvironmentStrings Win32 API.

Open the registry key subkey under key. key is Win32::Registry object of parent key. You can use predefined key HKEY_*. desired and opt is access mask and key option.

For detail, see the MSDN.

If block is given, the key reg is yielded and closed automatically after the block exists.

Convert Time object or Integer object time into 64-bit FILETIME.

Convert registry type value type to readable string.

Convert 64-bit FILETIME integer wtime into Time object.