Archive: Confused by EnvVarUpdate "Remove" documentation


Confused by EnvVarUpdate "Remove" documentation
I'd like to set the environment variable "MYVAR" to the correct new value, however the documentation suggests that I must know what it was set to in order to remove it. In my case, I don't really care what it was or even if it existed, I simply want "MYVAR" to be "MYSTRING" when I am done. I most definitely don't want it to be "OLDRANDUMSTUFMYSTRING"

The example below from the manual suggests that I must add additional entries for MyApp-V0.99 V0.98 etc.

${EnvVarUpdate} $0 "PATH" "R" "HKLM" "C:\Program Files\MyApp-v1.0" ; Remove path of old rev


What am I missing?

-Joe


if you're setting / deleting your own environment variable, rather than adjusting an existing one such as the PATH environment variable, just DIY:


; include for some of the windows messages defines
!include "winmessages.nsh"

; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'

; set variable
WriteRegExpandStr ${env_hklm} <var name> <var value>

; make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

; delete variable
DeleteRegValue ${env_hklm} <var name>

; make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

Thanks, that seemed to work nicely. I lightly edited your response and updated the wiki on sourceforge.