Environment variables have 4 contexts:
(do Win+R then type regedit to find the paths below)
- System variables (
HKLM\System\CurrentControlSet\Control\Session Manager\Environment
)
- User variables (
HKCU\Environment
)
- Process variables (not stored in the registry)
- Volatile variables (
HKCU\VolatileEnvironment
)
ref: https://rakhesh.com/windows/temp-environment-variable-has-a-2-or-other-number-after-it/
When the Group Policy Do not use temporary folders per session
isn't configured or isn't set to Enabled, the system will generate two Volatile Environment variables TEMP
& TMP
with the same value of the current user's TEMP
variable with the addition of an incremental number at the end of the TEMP folder (increments each time the user logs in, check @Damien's answer for details)
If you set the group policy Do not use temporary folders per session
to enabled, this behavior will not occur.