Talk:Environmental Variables: append, prepend, and remove entries

From NSIS Wiki
Jump to navigationJump to search

I have had reports of my installer overwriting the entire system path, rather than appending to it.

Has anyone else seen this happen ?

I can't reproduce the bug, but it has happened to at least two people from 2000 odd downloads of my software.

Maximum string length

Yes I also had reports concerning this problem and managed to reproduce it with a system path of more than 1024 characters, which is longer than the default maximum string length in NSIS. There should be error handling in EnvVarUpdate to prevent this. However, to correctly adapt the path, you will need to build NSIS with a greater string maximum length anyway (a special build with 8192 bytes is available).

Froesccn 12:56, 12 February 2009 (UTC)

Thanks Froesccn. I could reproduce it with >1024 paths as well. I rebuilt using the large string version of NSIS and the problem went away. I guess a note of this should be made pretty clear in the wiki page ? Using the short string version of NSIS and this code will result in the system path being cleared. Not fun explaining that to a user.

Installer/Uninstaller Examples

Where do the examples go in the installer script? Inside of the Section/SectionEnd? sag47

Overwrite entries

I have a suggestion to extend the function with the overwrite option. In the most cases the environmental variables need to be fully replaced by a new value, but the existing features do not enable that nor the combinations of them

The following lines of code could resolve that

 ${If} $2 == "O"  ;   If Action = Overwrite
   StrCpy $0 $4   ;   just copy PathString to EnvVar
   DetailPrint "Target was overwritten to $1"
 ${Else}

AVak 86.125.145.181 10:34, 15 October 2012 (UTC)

Bug when appending/prepending

There is a bug at appending/prepending operations at three places.

   ...
   StrCpy $0 $0;$7                    ;    append path to $0 with a prepended semicolon
   ...
   StrCpy $0 $0;$4                      ;     append PathString
   ...
   StrCpy $0 $4;$0                      ;     prepend PathString
   ...

In all three cases the source must be between double quotes:

   ...
   StrCpy $0 "$0;$7"                    ;    append path to $0 with a prepended semicolon
   ...
   StrCpy $0 "$0;$4"                      ;     append PathString
   ...
   StrCpy $0 "$4;$0"                      ;     prepend PathString
   ...

UniIntel, 10:00, 28 January 2013 (UTC)

Actually, as the NSIS parser is token based, you don't need quotes. Try DetailPrint something;else in a test script --kichik 18:12, 28 January 2013 (UTC)

Needs updated for 1229 changes

https://sourceforge.net/p/nsis/bugs/1229/