module Chef::Mixin::WindowsEnvHelper

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/mixin/windows_env_helper.rb, line 42
def broadcast_env_change
  flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
  # for why two calls, see:
  # http://stackoverflow.com/questions/4968373/why-doesnt-sendmessagetimeout-update-the-environment-variables
  if SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string("Environment").address, flags, 5000, nil) == 0
    Chef::ReservedNames::Win32::Error.raise!
  end
  if SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string(
    utf8_to_wide("Environment")
  ).address, flags, 5000, nil) == 0
    Chef::ReservedNames::Win32::Error.raise!
  end
end
expand_path(path) click to toggle source
# File lib/chef/mixin/windows_env_helper.rb, line 56
def expand_path(path)
  # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724265%28v=vs.85%29.aspx
  # Max size of env block on windows is 32k
  buf = 0.chr * 32 * 1024
  if ExpandEnvironmentStringsA(path, buf, buf.length) == 0
    Chef::ReservedNames::Win32::Error.raise!
  end
  buf.strip
end