Created
August 28, 2009 13:17
-
-
Save bosko/176980 to your computer and use it in GitHub Desktop.
A way to change environment variables in Windows and notify processes about change.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Not my idea. Don't remember where I've picked it up. | |
# Just stored here for future reference. | |
require 'win32/registry.rb' | |
require 'Win32API' | |
Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_WRITE) do |reg| | |
reg['my_value'] = '123' | |
end | |
SendMessageTimeout = Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L') | |
HWND_BROADCAST = 0xffff | |
WM_SETTINGCHANGE = 0x001A | |
SMTO_ABORTIFHUNG = 2 | |
result = 0 | |
SendMessageTimeout.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', SMTO_ABORTIFHUNG, 5000, result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment