I have read quite a lot of the forum relating setting/reading/removing environment variables. In particular I am using code from the following thread:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
The file is called writeenvstr.nsh.txt and it’s quite popular as it’s been downloaded 176 times.
I have a few questions.
(1)The code writes the environment variable ok but writes it to “User variablesâ€, how do I write to “System variablesâ€?
For example I want to add something to the end of “PATH†which is in “System variables†How would this be done? Would it be a matter of getting the current path (e.g. ReadEnvStr $0 PATH) and then concatenating ;some\path\ to the end of it.
(2) How do you remove an environment variable?
I mean do you pop the variable on the stack and then call “un.DeleteEnvStr†for each environment variable that you have set? What would the code look like?
Pop SOMEVARIABLE1
Call un.DeleteEnvStr
Pop SOMEVARIABLE2
Call un.DeleteEnvStr
…
Pop SOMEVARIABLEn
Call un.DeleteEnvStr
(3) Once an environment variable has been written is cannot be read until you reboot.
For example:
Push "SOMEDIR"
Push "C:\Some\Directory"
Call WriteEnvStr
After writing an environment variable, this read
only works after a reboot.
ReadEnvStr $0 "Path"
MessageBox MB_OK $0
Obviously this is no good.
Am I doing something wrong?