summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-05-21 14:40:08 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-05-26 12:21:39 -0700
commitb5bb5c9776bf5401bcb34d54f80be57c720c17e2 (patch)
treec9008dd34d4abd823ab34c90a737077ae1530ae9
parent4d1e0dcaded37365e41c567e2b31fdd34e8695ed (diff)
downloadchef-b5bb5c9776bf5401bcb34d54f80be57c720c17e2.tar.gz
add unicode WM_SETTINGCHANGE broadcast
helps powershell pick up the env change settings.
-rw-r--r--lib/chef/mixin/windows_env_helper.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/mixin/windows_env_helper.rb b/lib/chef/mixin/windows_env_helper.rb
index 490b235065..2b59a6abfb 100644
--- a/lib/chef/mixin/windows_env_helper.rb
+++ b/lib/chef/mixin/windows_env_helper.rb
@@ -21,11 +21,11 @@ require 'chef/exceptions'
require 'chef/platform/query_helpers'
require 'chef/win32/error' if Chef::Platform.windows?
require 'chef/win32/api/system' if Chef::Platform.windows?
+require 'chef/win32/api/unicode'
class Chef
module Mixin
module WindowsEnvHelper
-
if Chef::Platform.windows?
include Chef::ReservedNames::Win32::API::System
end
@@ -39,7 +39,16 @@ class Chef
def broadcast_env_change
flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
- SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil)
+ # 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(
+ Chef::ReservedNames::Win32::Unicode.utf8_to_wide('Environment')
+ ).address, flags, 5000, nil) == 0 )
+ Chef::ReservedNames::Win32::Error.raise!
+ end
end
def expand_path(path)