PDA

View Full Version : Environment Variable question



kboller
11-01-2017, 10:14 AM
I am trying to set environment variables during an install in order to pass them to PowerShell scripts that communicate with a SQL server instance during setup. It doesn’t appear that SetupBuilder updates the environment variables at all. Here is what I found in the documentation:

“On Windows NT-based systems, environment modification information is stored in the registry and a message notifies the system of changes when the installation completes. Any new processes, or existing processes that check for these messages, use the new or updated environment variables.”

Does this mean that environment variables will not be updated until the SetupBuilder dialog completes? And if so, is there a way to force SetupBuilder to update the environment variables immediately so that I can pass them to my PowerShell script that checks for a specific environment variable.

Thanks,

Kurt

linder
11-02-2017, 09:35 AM
Hi Kurt,

In Windows, modifications to the environment variables do not result in immediate change. For example, by default, if you start a Command Prompt after making the changes, the environment variables will reflect the previous (not the current!) values. The changes do not take effect until you log off and then log back on.

To effect these changes without having to log off, SetupBuilder broadcasts a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications can perform an update. But if an application does not handle this message, the environment variables will still reflect the previous (not the current) values.

That is by Windows design and expected. I have created an example (please see the attached screenshots): the Command Prompt on Windows 10 (BEFORE.PNG) shows the environment variable "Path". We run a SetupBuilder installer to append "C:\yada" to the PATH variable. We display a simple Message Box so the installer does not continue. When we do again a SET in the same Command Prompt session, then PATH still has its "old" value. But when we start a new command prompt and do a SET, then you'll see the new value (AFTER.PNG).

Does this help?

Friedrich

kboller
11-06-2017, 10:18 PM
Yes, Thanks.