Skip to content
⌘ NSIS Forum Archive

%PATH% - Forcing Update in Installer Session

3 posts

PaddyK#

%PATH% - Forcing Update in Installer Session

Hello,

Has anyone had success updating the Windows PATH environment variable during an NSIS installer session, and actually being able to see the effect (i.e. running an exe/bat) with respect to the updated path during the *same* installer session?

I'm trying to code a section that calls a MySQL 5.5 binary, installs MySQL 5.6, updates the path (i.e. [-] the 5.5 bin path and [+] the 5.6 bin path), and then proceeds to call the same binary from MySQL 5.6, all without having to restart the installer to soak up the PATH change.

I've tried the following without any luck:

WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "${new_path}"

SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=1

Any help would be greatly appreciated, thank you!
jpderuiter#
I think you should increase the timeout with WM_WININICHANGE.
1 millisecond seems a bit short...

But
Originally Posted by Wiki
WARNING: Strings longer than ${NSIS_MAX_STRLEN} will get truncated/corrupted. Do NOT use this function to update %PATH%
See also http://forums.winamp.com/showthread.php?t=301602
Anders#
  • Writing to the registry only changes the environment for new users logging in.
  • WM_WININICHANGE "Environment" suggests to listening applications that they should update their environment from the registry, Explorer.exe is pretty much the only application that does this and because Explorer is such a good citizen all applications launched from the shell gets the updated environment.
  • To update yourself (the installer process) you have to call Kernel32::SetEnvironmentVariable directly with the system plugin.