Reputation: 22080
I'm setting permanent environment variables from an NSIS installer like described in the NSIS wiki. That works as expected, the variable is available to new processes after the installation.
However, when using the option to launch the installed program at the end of the installation, the environment variable is not available for that program started from the installer. I assume this is because the program started there has the installer process as parent and gets the same environment block (see the lpEnvironment argument of the createProcess function).
How can I make the program started from the last page of the installer see the newly set environment variable? Writing a custom launch function instead? The documentation does not say anything about the environment block of the Exec
function.
Upvotes: 1
Views: 1389
Reputation: 101764
You also need to use the Setting Environmental Variables Temporarily code if you want child processes to inherit the (updated) environment because only explorer.exe responds to the WM_WININICHANGE notification.
outfile "test.exe"
name "run env test"
requestexecutionlevel user
!define MUI_FINISHPAGE_RUN "cmd.exe"
!define MUI_FINISHPAGE_RUN_PARAMETERS "/k set foobar"
!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section
System::Call 'Kernel32::SetEnvironmentVariable(t "FooBar",t "BazBlargh")i'
SectionEnd
Upvotes: 2