Skip to content
⌘ NSIS Forum Archive

Complete removal of environment variable?

5 posts

mabian#

Complete removal of environment variable?

Hello,

I'm trying complete deletion of an environment variable on uninstall, using this command:

${un.EnvVarUpdate} $0 ${C_PGENVVARIABLE} "R" "HKLM" "$INSTDIR\etc"

Of course C_PGENVARIABLE holds the name of the variable.

The variable is emptied but not removed. Is there an easy way to force complete variable removal?

Thanks,
Mario
Animaether#
Just delete the registry value, then signal to windows you changed things around:

/* all users */
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "YourValueName"
/* or current user */
DeleteRegValue HKCU "Environment" "YourValueName"
/* signal the change - defines are in WinMessages.nsh */
  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 
mabian#
Oh, that's cool: no more need for ${envUpdate} then, just Write and Delete registry keys 🙂

Thank you,
Mario
mabian#
Oh, that's cool: no more need for ${envUpdate} then, just Write and Delete registry keys 🙂

Thank you,
Mario
Animaether#
Yup. EnvVarUpdate is more useful if you have something like the PATH environment variable where there are multiple values that you'd want to manipulate. Deleting the PATH environment variable would be a Bad Thing™ 😉