diff options
author | Joshua Timberman <joshua@opscode.com> | 2012-09-26 15:18:39 -0700 |
---|---|---|
committer | Joshua Timberman <joshua@opscode.com> | 2012-09-26 15:18:39 -0700 |
commit | 5abd700bf778c8e2ebe755f894bc529805951ce5 (patch) | |
tree | cf218ccf2fcda4e829fa25a9d54d428a28333318 | |
parent | 04128419efe6b274facb25f75b377885e9a93451 (diff) | |
parent | b913f4a2cd2036a7df628eacde72d9b594fe6478 (diff) | |
download | mixlib-shellout-5abd700bf778c8e2ebe755f894bc529805951ce5.tar.gz |
Merge pull request #9 from schubergphilis/master
[COOK-1584] windows_registry should support all registry types
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | libraries/registry_helper.rb | 17 | ||||
-rw-r--r-- | resources/registry.rb | 2 |
4 files changed, 32 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e803fa2..2bf4acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ * [COOK-666] `windows_package` should support CoApp packages * windows_registry :force_modify action should use RegNotifyChangeKeyValue from WinAPI * WindowsRebootHandler/`windows_reboot` LWRP should support kicking off subsequent chef run on reboot. -* Support all types of registry keys with `type` parameter in `windows_registry`. ## v1.3.4: @@ -278,7 +278,17 @@ Creates and modifies Windows registry keys. - key_name: name attribute. The registry key to create/modify. - values: hash of the values to set under the registry key. The individual hash items will become respective 'Value name' => 'Value data' items in the registry key. -- type: Type of key to create, currently only used for :binary to create `REG_BINARY` registry keys. Must be a symbol. See __Roadmap__ for future plans. +- type: Type of key to create, defaults to REG_SZ. Must be a symbol, see the overview below for valid values. + +### Registry key types + +- :binary: REG_BINARY +- :string: REG_SZ +- :multi_string: REG_MULTI_SZ +- :expand_string: REG_EXPAND_SZ +- :dword: REG_DWORD +- :dword_big_endian: REG_DWORD_BIG_ENDIAN +- :qword: REG_QWORD ### Examples @@ -300,6 +310,12 @@ Creates and modifies Windows registry keys. action :remove end + # Add a REG_MULTI_SZ value to the registry + windows_registry 'HKCU\Software\Test' do + values 'MultiString' => ['line 1', 'line 2', 'line 3'] + type :multi_string + end + ### Library Methods Registry.value_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','BGINFO') diff --git a/libraries/registry_helper.rb b/libraries/registry_helper.rb index 1c683d5..1b3a69c 100644 --- a/libraries/registry_helper.rb +++ b/libraries/registry_helper.rb @@ -105,12 +105,23 @@ module Windows end if cur_val != val Chef::Log.debug("setting #{key}=#{val}") + if type.nil? - reg[key] = val - else - reg[key, ::Win32::Registry::REG_BINARY] = val + type = :string end + reg_type = { + :binary => ::Win32::Registry::REG_BINARY, + :string => ::Win32::Registry::REG_SZ, + :multi_string => ::Win32::Registry::REG_MULTI_SZ, + :expand_string => ::Win32::Registry::REG_EXPAND_SZ, + :dword => ::Win32::Registry::REG_DWORD, + :dword_big_endian => ::Win32::Registry::REG_DWORD_BIG_ENDIAN, + :qword => ::Win32::Registry::REG_QWORD + }[type] + + reg.write(key, reg_type, val) + ensure_hive_unloaded(hive_loaded) changed_something = true diff --git a/resources/registry.rb b/resources/registry.rb index b891b13..1289dbf 100644 --- a/resources/registry.rb +++ b/resources/registry.rb @@ -24,7 +24,7 @@ actions :create, :modify, :force_modify, :remove attribute :key_name, :kind_of => String, :name_attribute => true attribute :values, :kind_of => Hash -attribute :type, :kind_of => Symbol, :default => nil, :equal_to => [:binary] +attribute :type, :kind_of => Symbol, :default => nil, :equal_to => [:binary, :string, :multi_string, :expand_string, :dword, :dword_big_endian, :qword] def initialize(name, run_context=nil) super |