Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell environment variables are not updated

Tags:

powershell

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

like image 262
nomail Avatar asked Jan 15 '13 06:01

nomail


2 Answers

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

like image 191
Burt_Harris Avatar answered Nov 15 '22 04:11

Burt_Harris


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

like image 26
Loïc MICHEL Avatar answered Nov 15 '22 04:11

Loïc MICHEL