summaryrefslogtreecommitdiff
path: root/lib/chef/monkey_patches/win32/registry.rb
blob: 9471777c573614aef4c6175de3b4875953756820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

require 'chef/win32/api/registry'
require 'chef/win32/unicode'
require 'win32/registry'

module Win32
  class Registry
    module API
      
      extend Chef::ReservedNames::Win32::API::Registry

      module_function

      if RUBY_VERSION =~ /^2\.1/
        # ::Win32::Registry#delete_value is broken in Ruby 2.1 (up to Ruby 2.1.6).
        # This should be resolved in a later release (see note #9 in link below).
        # https://bugs.ruby-lang.org/issues/10820
        def DeleteValue(hkey, name)
          check RegDeleteValueW(hkey, name.to_wstring)
        end
      end

      # ::Win32::Registry#delete_key uses RegDeleteKeyW. We need to use
      # RegDeleteKeyExW to properly support WOW64 systems.
      def DeleteKey(hkey, name)
        check RegDeleteKeyExW(hkey, name.to_wstring, 0, 0)
      end
      
    end
  end
end