Search code examples
windowspathinstallationenvironment-variablesnsis

Update %PATH% environment variable using NSIS


I've read that "Strings longer than ${NSIS_MAX_STRLEN} (1024) will get truncated/corrupted."

How can I safely update %PATH% environment variable?


Solution

  • You can use an alternative NSIS build from the special builds page like the large strings build that defines NSIS_MAX_STRLEN=8192 and should prevent you from breaking the host path.

    In practice, on a desktop machine, 1024 byte seems enough, but on a development host with many tools installed (like mine), the path might be broken after manipulation, while the 8192 bytes strings build had never perturbed my machine.

    To be very sure, you can add a check on the path length before manipulation and abort the installer with a message in the case where the path would be close to the NSIS_MAX_STRLEN constant before trying to manipulate it.