I've have wix installer that updates environment variable using <Environment />
element.
The environment variable value is updated in registry. But when I try to open Powershell it doesn't see any changes unless I reboot my PC.
Does anyone have any thoughts about why/how and how can I avoid reboot. Thanks in advance, nomail
Update: I've found why this is happening. It turns out that the session variables are updated on reboot or if a system broadcast message is sent. To send a broadcast message
SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment");
Another dirty way to send a message is to use SETX
command that will write new value to environment variables and update session info
SETX something_that_is_not_important value_that_is_not_important
Mind you that you will still have to close and open CommandLine or PowerShell console
Explorer.exe
is the only common such process. Thus any new processes created by Explorer will have the updated environment, other processes already running before the broadcast will generally not be updated.WM_SETTINGCHANGE
message. This is why a new PowerShell or cmd shell will pickup environment changes using that tool. As @Richard says, this broadcast is understood and propagated because it's happening within the Explorer.exe shell. The registry editor, or other tool to inject new environment variables into the registry, have no method to force the update. So your option #1 of sending the broadcast message is viable and I wouldn't consider it "dirty".WixBroadcastSettingChange
. Which does the job. You use it like<CustomActionRef Id="WixBroadcastSettingChange" />