No Environment Change Notification when Reboot Required

The documentation for the WriteEnvironmentStrings action states,

Note that environment variables do not change for the installation in progress when either the WriteEnvironmentStrings action or RemoveEnvironmentStrings action are run. On Windows 2000, this information is stored in the registry and a message is sent to notify the system of changes when the installation completes. A new process, or another process that checks for these messages, uses the new environment variables.

This means that Windows Installer will broadcast the WM_SETTINGCHANGE message to all top-level windows with the LPARAM value of “Environment”.

This message is not broadcast, however, if a reboot is required to replace a file after reboot that was in use during the same installer transaction. This would cause Windows Installer to return ERROR_SUCCESS_REBOOT_INITIATED (1641) or ERROR_SUCCESS_REBOOT_REQUIRED (3010) – depending on the value of the REBOOT property – and that should be honored to make sure the application will work correctly and securely.

If you’re an applications developer that wants to take advantage of this environment notification to update your process with changes to the environment variables, handle the WM_SETTINGCHANGE (0x001A) notification message in your top-level window procedure and check that the LPARAM is “Environment”. You can then enumerate the environment variables from the registry and call SetEnvironmentVariable to update all or a subset of environment variables in your process. In managed code you can use the Environment.GetEnvironmentVariable(string, EnvironmentVariableTarget) or Environment.GetEnvironmentVariables(EnvironmentVariableTarget) method to easily retrieve environment variables from the registry and Environment.SetEnvironmentVariable to set them in  your process.