diff options
author | Salim Alam <salam@chef.io> | 2015-08-27 12:50:36 -0700 |
---|---|---|
committer | Salim Alam <salam@chef.io> | 2015-08-27 12:50:36 -0700 |
commit | 397e983aba9c1dd8e590da31a54a84da812c5e9a (patch) | |
tree | 5a788c1c365a5533c2503d96b6c687e366bb86cc | |
parent | 10e6a75cfaa04aecee578dd3173173f5aac5ea31 (diff) | |
download | chef-397e983aba9c1dd8e590da31a54a84da812c5e9a.tar.gz |
Switch RegDeleteKeyEx to use FFI
-rw-r--r-- | lib/chef/win32/api/registry.rb | 38 | ||||
-rw-r--r-- | lib/chef/win32/registry.rb | 12 |
2 files changed, 48 insertions, 2 deletions
diff --git a/lib/chef/win32/api/registry.rb b/lib/chef/win32/api/registry.rb new file mode 100644 index 0000000000..9d813cef3e --- /dev/null +++ b/lib/chef/win32/api/registry.rb @@ -0,0 +1,38 @@ +# +# Author:: Salim Alam (<salam@chef.io>) +# Copyright:: Copyright 2015 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/win32/api' + +class Chef + module ReservedNames::Win32 + module API + module Registry + extend Chef::ReservedNames::Win32::API + + ############################################### + # Win32 API Bindings + ############################################### + + ffi_lib 'advapi32' + + safe_attach_function :RegDeleteKeyExA, [ :HKEY, :LPCTSTR, :LONG, :DWORD ], :LONG + + end + end + end +end
\ No newline at end of file diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb index 1a1aa12fad..9fb13f505c 100644 --- a/lib/chef/win32/registry.rb +++ b/lib/chef/win32/registry.rb @@ -17,6 +17,7 @@ # limitations under the License. # require 'chef/reserved_names' +require 'chef/win32/api/registry' if RUBY_PLATFORM =~ /mswin|mingw32|windows/ require 'win32/registry' @@ -27,6 +28,9 @@ class Chef class Win32 class Registry + include Chef::ReservedNames::Win32::API::Registry + extend Chef::ReservedNames::Win32::API::Registry + attr_accessor :run_context attr_accessor :architecture @@ -142,9 +146,13 @@ class Chef #Using the 'RegDeleteKeyEx' Windows API that correctly supports WOW64 systems (Win2003) #instead of the 'RegDeleteKey' def delete_key_ex(hive, key) - regDeleteKeyEx = ::Win32::API.new('RegDeleteKeyEx', 'LPLL', 'L', 'advapi32') hive_num = hive.hkey - (1 << 32) - regDeleteKeyEx.call(hive_num, key, ::Win32::Registry::KEY_WRITE | registry_system_architecture, 0) + begin + RegDeleteKeyExA(hive_num, key, ::Win32::Registry::KEY_WRITE | registry_system_architecture, 0) + return true + rescue ::Win32::Registry::Error => e + return false + end end def key_exists?(key_path) |