Class: Win32::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/monkey_patches/win32/registry.rb

Defined Under Namespace

Modules: API

Instance Method Summary collapse

Instance Method Details

#write(name, type, data) ⇒ Object

::Win32::Registry#write does not correctly handle data in Ruby 2.1 (up to Ruby 2.1.6). bugs.ruby-lang.org/issues/11439



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/monkey_patches/win32/registry.rb', line 51

def write(name, type, data)
  case type
  when REG_SZ, REG_EXPAND_SZ
    data = data.to_s.encode(WCHAR) + WCHAR_NUL
  when REG_MULTI_SZ
    data = data.to_a.map { |s| s.encode(WCHAR) }.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL
  when REG_BINARY
    data = data.to_s
  when REG_DWORD
    data = API.packdw(data.to_i)
  when REG_DWORD_BIG_ENDIAN
    data = [data.to_i].pack("N")
  when REG_QWORD
    data = API.packqw(data.to_i)
  else
    raise TypeError, "Unsupported type #{type}"
  end
  API.SetValue(@hkey, name, type, data, data.bytesize)
end