当使用如下的方式添加系统环境变量的Path的时候,有时候会删除以前的内容:
ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R0;$INSTDIR"
具体参见https://nsis.sourceforge.io/Path_Manipulation:
Warning : this code will replace paths rather than append if the existing path exceeds the maximum string length in the NSIS build you are using. Some setup crash can also occurs.
使用EnVar_plugin组件可解决问题:
;增加
EnVar::SetHKLM
EnVar::AddValue "Path" "$INSTDIR"
;删除
EnVar::SetHKLM
EnVar::Check "Path" "$INSTDIR"
Pop $0
${If} $0 = 0
MessageBox MB_OK "Already there"
${EndIf}
MessageBox MB_OK $0
EnVar::DeleteValue "Path" "$INSTDIR"
7479

被折叠的 条评论
为什么被折叠?



