Archive: Problems adding Path variable


Problems adding Path variable
Hello!

I want to add a path to the path environment variable in order to call executables without defining the whole path.

I use the code sample at:

http://nsis.sourceforge.net/Path_Manipulation

But those lines don't really work as I would like to have. Indeed, the path variable is going to be added. BUT: If I again call ReadEnvStr $1 PATH, my set path variable is not found in $1. If I call my installer several times without rebooting the computer, the path variable is added several times due to ReadEnvStr $1 PATH. I have to reboot the machine to get the right path informations. It seems, that SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 does not refresh the system correctly. What can be done to refresh the system without rebooting? I use NSIS 2.14.


Re:
I found out that the following lines

WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

do not immediately activate the new set path.

So if you set a path and then execute an executable without path, that will not work.

e.g.
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
Exec 'InstallAppCmd.exe' # FAILES!!!
but
Exec 'C:\Program Files\InstallAppCmd.exe' # works!!!


The SendMessage line only updates explorer.exe. If you execute your installer from an application that doesn't update itself due to that broadcast message, like another installer, your installer will not see the updated environment variable. To set the environment variables of the current process, you can use the first method described in Setting Environment Variables. When setting the variables for the current process, every process executed from it will inherit the new variables. However, they will not be set on the entire system and will be forgotten when the process exits.