TEMP% has different values for a Windows Service running as Local System
Blog post from Octopus Deploy
Paul Stovell discusses an issue encountered with Windows Services running under the SYSTEM account, where environment variables behave differently than expected. Typically, user-defined environment variables override machine scope values, but when services run as the SYSTEM account, the %TEMP% variable defaults to C:\Windows\TEMP instead of the user-specific path. This anomaly led to a bug in a pre-release version of Octopus Deploy, where environment variables were supposed to update automatically before each script run without restarting the Tentacle windows service. Stovell speculates that this behavior might be a backward compatibility feature for older Windows Services. He notes that services inherit environment variables from their parent processes, with wininit.exe setting TEMP to C:\Windows\TEMP, and mentions that a patch will be released to address the issue.