Class: Chef::Provider::Env::Windows
- Inherits:
-
Chef::Provider::Env
- Object
- Chef::Provider
- Chef::Provider::Env
- Chef::Provider::Env::Windows
- Defined in:
- lib/chef/provider/env/windows.rb
Constant Summary collapse
- HWND_BROADCAST =
0xffff
- WM_SETTINGCHANGE =
0x001A
- SMTO_BLOCK =
0x0001
- SMTO_ABORTIFHUNG =
0x0002
- SMTO_NOTIMEOUTIFNOTHUNG =
0x0008
Instance Attribute Summary
Attributes inherited from Chef::Provider::Env
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #run_context
Instance Method Summary collapse
- #broadcast_env_change ⇒ Object
- #create_env ⇒ Object
- #delete_env ⇒ Object
- #env_obj(key_name) ⇒ Object
- #env_value(key_name) ⇒ Object
Methods inherited from Chef::Provider::Env
#action_create, #action_delete, #action_modify, #compare_value, #delete_element, #env_key_exists, #initialize, #load_current_resource, #modify_env
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #cookbook_name, #initialize, #load_current_resource, #node, #resource_collection
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
This class inherits a constructor from Chef::Provider::Env
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#broadcast_env_change ⇒ Object
66 67 68 69 70 71 |
# File 'lib/chef/provider/env/windows.rb', line 66 def broadcast_env_change result = 0 flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG @send_message ||= Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L') @send_message.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', flags, 5000, result) end |
#create_env ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chef/provider/env/windows.rb', line 29 def create_env obj = env_obj(@new_resource.key_name) unless obj obj = WIN32OLE.connect("winmgmts://").get("Win32_Environment").spawninstance_ obj.name = @new_resource.key_name obj.username = "<System>" end obj.variablevalue = @new_resource.value obj.put_ broadcast_env_change end |
#delete_env ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/chef/provider/env/windows.rb', line 41 def delete_env obj = env_obj(@new_resource.key_name) if obj obj.delete_ broadcast_env_change end end |
#env_obj(key_name) ⇒ Object
54 55 56 57 |
# File 'lib/chef/provider/env/windows.rb', line 54 def env_obj(key_name) WMI::Win32_Environment.find(:first, :conditions => { :name => key_name }) end |
#env_value(key_name) ⇒ Object
49 50 51 52 |
# File 'lib/chef/provider/env/windows.rb', line 49 def env_value(key_name) obj = env_obj(key_name) return obj ? obj.variablevalue : nil end |