Why does %TEMP% resolve to a non-deterministic path of the form %TEMP\\<digit>?

淺唱寂寞╮ 提交于 2019-11-30 00:31:06
Damien_The_Unbeliever

Explanation, discussion, workarounds, etc, all under the Old New Thing article Why does the name of my TEMP directory keep changing - it ensures multiple terminal services sessions for the same user don't (by default) share a temp directory.

The problem lay in the Administrative Templates\Windows Components\Terminal Services\Temporary folders group policy. If you don't select Do not use temporary folders per session, then these TEMP subdirectories are created. There is also a knowledge base article describing the registry keys behind these group policies.

Personally, I find the first comment in reply to be the most useful:

Why does it matter if the temp location jumps around anyway, it's temporary!

See also

Environment variables have 4 contexts:

(do Win+R then type regedit to find the paths below)

  1. System variables (HKLM\System\CurrentControlSet\Control\Session Manager\Environment)
  2. User variables (HKCU\Environment)
  3. Process variables (not stored in the registry)
  4. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!