Class: Chef::Provider::Env::Windows

Inherits:
Chef::Provider::Env show all
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

#key_exists

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

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, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #load_current_resource, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?

Methods included from DSL::Recipe

#method_missing

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

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::DSL::Recipe

Instance Method Details

#broadcast_env_changeObject



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_envObject



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_envObject



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