Search code examples
nsis

NSIS and PATH env variables


In my installer, I embed cmake and others installers. During installation the user install, through my installer, cmake and add cmake to the path.

At this point if I open a command prompt and type cmake, it is actually recognized.

But in the installer I run the following command:

ReadEnvStr $1 %COMSPEC%
ExecWait '"$1" /c cmake XXX'

But it tells me cmake isn't recognized. How is that possible? I just open a command prompt before in c:/windows/system32/cmd.exe and type cmake and it was recognized so why this code does not work?

It is like the paths env variables was not updated somehow. Of course if I reboot it works fine but I would like to avoid it.

Thanks for your help.


Solution

  • Environment variables are inherited from their parent process by default. Explorer.exe is the only application that listens for environment changes and therefore if you start a new process from the start menu it will run with the updated environment.

    You can update the installer process environment and it will be passed to the ExecWait child:

    System::Call 'kernel32::SetEnvironmentVariable(t "foo", t "bar")'
    

    When dealing with long path strings you really should be using the EnvVar plug-in.