# class Chef::Provider::Env::Windows

### Constants

HWND_BROADCAST

  see: msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx

SMTO_ABORTIFHUNG
SMTO_BLOCK
SMTO_NOTIMEOUTIFNOTHUNG
WM_SETTINGCHANGE

### Public Instance Methods

broadcast_env_change() click to toggle source

    # 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() click to toggle source

    # 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() click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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