8

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

4
  • 2
    Note that broadcast message works only for processes that process it. 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. Commented Jan 15, 2013 at 10:26
  • Updating the environment via the the control panel applet (System Properties -> Advanced -> Environment Variables) broadcasts the 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". Commented Jul 1, 2014 at 23:38
  • Yep, the first option is the proper way of propagating environment variables. I meant that the second option is a 'dirty hack' which I must admit I used once. Commented Jul 3, 2014 at 6:40
  • Starting with 3.10 WIX has CustomAction WixBroadcastSettingChange. Which does the job. You use it like <CustomActionRef Id="WixBroadcastSettingChange" /> Commented Nov 6, 2015 at 8:22

2 Answers 2

2

This is almost certainly because of a missing a <WriteEnvironmentStrings> element in the <InstallExecuteSequence> section of your WIX file. That custom action is responsible for sending the broadcast WM_SETTINGSCHANGE message.

This isn't exactly a bug in the WIX, rather a poorly documented requirement. To effectively use WIX you also have to understand the Windows Installer Database reference docs, not just the XML. In the MSDN topic on the Environment Table the need to invoke the WriteEnvironmentStrings and RemoveEnvironmentStrings custom actions is described, but in terminology that may be foreign to someone without native MSI background.

An article showing this is at http://blogs.technet.com/b/alexshev/archive/2008/03/28/from-msi-to-wix-part-13-installable-items-environment-variable.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, my experiences writing this installer do not match what you are claiming. Even though I was using WriteEnvironmentStrings, I still had to add a custom action that broadcasts the message, or else the thing I added to the PATH would not be picked up by new Command Prompts after the installer is done. The documentation does say WriteEnvironmentSettings broadcasts that message though. Hmm.
I don't understand what happened in your case David. Could it have been related to system vs. user environment strings, and permissions used when installing?
1

seems to be a specific wix problem, see comments at the bottom of : this page

1 Comment

It's not exactly a WIX problem. It's the way the environment variables are loaded. They don't refer to registry directly rather are loaded during system start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.