(This question is similar to Delphi: How to respond to WM_SettingChange/WM_WinIniChange? but for the AutoHotKey language. This is not about sending WM_SETTINGCHANGE from inside AutoHotKey.)
In another Windows process ("sender"), I change the PATH environment variable by modifying the HK_CURRENT_USER registry. Then I send/publish a WM_SETTINGCHANGE message using the SendMessageTimeout API.
My concurrently running AutoHotKey script ("receiver"), which I use as a program launcher, does not seem to be aware of the change. I want to capture this message in order to refresh the script's local copy of the PATH variable. Is it possible?
For example, the "sender" could be the System Properties dialog box, or some another AutoHotKey script:
EnvUpdate
or some other handy third-party Windows binary like nircmd:
nircmd sysrefresh environment
or some Ruby code :
### This is a -*- ruby -*- script
require 'Win32API'
module Windows::EnvByReg
def self.envupdate()
result = 0
wParam_unused = 0
timeout_ms = 5000
SendMessageTimeout.call(HWND_BROADCAST, WM_SETTINGCHANGE,
wParam_unused, 'Environment',
SMTO_ABORTIFHUNG, timeout_ms, result)
end
SendMessageTimeout = Win32API.new('user32', 'SendMessageTimeout',
'LLLPLLP', 'L')
HWND_BROADCAST = 0xffff
WM_SETTINGCHANGE = 0x001A
SMTO_ABORTIFHUNG = 2
end#module
if __FILE__ == $PROGRAM_NAME
Windows::EnvByReg.envupdate
end