windowsnsistemp

Seems that $TEMP folder path in NSIS does not match %TEMP% windows variable


I inherited a project that I'm trying to update. It uses NSIS 3.0b2 (I also tried with 3.08 and had the same issue).

I'm trying to download a file (valid URL) to the $TEMP variable, however I see a "copy failed" error.

By printing the $TEMP variable I see that it is "C:\Users\JSMITH~1\AppData\Local\Temp" (note, Using John Smithy as an example username)

This style user folder doesn't seem to exist on my machine. %temp% takes me to "C:\Users\jsmithy\AppData\Local\Temp"

Presumably that is the expected folder for $TEMP in my .nsh script. This was probably originally designed for windows 7 and now its running on windows 10. I assumed NSIS 3.08 would fix that since 3.0b2 was a beta release for win10 but I see the same $temp path.

Is this defined anywhere? What is the proper way to fix this path? (I've seen posts that just create a new variable, but I'm more curious about where NSIS is pulling the "old style" username from that doesn't seem supported anymore).

"old style" meaning Users\JSMITH~1 vs. "new style" Users\jsmithy


Solution

  • NSIS calls GetTempPath to resolve $temp. A filename ending with ~1 indicates a short name, you would have to ask Microsoft why they are returning the short name, probably for compatibility.

    If you really want the long name you can do

    System::Call 'kernel32::GetLongPathName(t"$temp", t.r1, i${NSIS_MAX_STRLEN})'
    MessageBox MB_OK $1