Powershell environment variables are not updated

Question:

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

Another dirty way to send a message is to use SETX command that will write new value to environment variables and update session info

Mind you that you will still have to close and open CommandLine or PowerShell console

Answer:

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

Source:

Powershell environment variables are not updated by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply