windows 为什么 %TEMP% 解析为 %TEMP\<digit> 形式的非确定性路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6521277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does %TEMP% resolve to a non-deterministic path of the form %TEMP\<digit>?
提问by shacharsa
I have a Windows Server 2008 32 bit and when I'm typing %temp% it takes me to ..AppData\Local\Temp\1\ or ..AppData\Local\Temp\2 instead of ..AppData\Local\Temp
我有一个 Windows Server 2008 32 位,当我输入 %temp% 时,它会将我带到 ..AppData\Local\Temp\1\ 或 ..AppData\Local\Temp\2 而不是 ..AppData\Local\Temp
I've already checked the Environment Variables and they are ok.
我已经检查了环境变量,它们没问题。
I'm asking that because I have an application that's supposed to copy files to %temp%\my application and instead it copies the files to %temp%\1\my application
我之所以这么问是因为我有一个应用程序应该将文件复制到 %temp%\my application,而是将文件复制到 %temp%\1\my application
Does someone have a solution for that?
有人有解决方案吗?
回答by 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.
解释、讨论、解决方法等,都在旧的新事物文章为什么我的 TEMP 目录的名称不断变化- 它确保同一用户的多个终端服务会话(默认情况下)不共享临时目录。
The problem lay in the Administrative Templates\Windows Components\Terminal Services\Temporary foldersgroup 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.
问题出在管理模板\Windows 组件\终端服务\临时文件夹组策略中。如果您不选择不使用每个会话的临时文件夹,则会创建这些 TEMP 子目录。还有一篇知识库文章描述了这些组策略背后的注册表项。
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
也可以看看
回答by Uentee
Environment variables have 4 contexts:
环境变量有 4 个上下文:
(do Win+R then type regedit to find the paths below)
(做 Win+R 然后输入 regedit 找到下面的路径)
- System variables (
HKLM\System\CurrentControlSet\Control\Session Manager\Environment
) - User variables (
HKCU\Environment
) - Process variables (not stored in the registry)
- Volatile variables (
HKCU\VolatileEnvironment
)
- 系统变量 (
HKLM\System\CurrentControlSet\Control\Session Manager\Environment
) - 用户变量 (
HKCU\Environment
) - 进程变量(不存储在注册表中)
- 易失性变量 (
HKCU\VolatileEnvironment
)
ref: https://rakhesh.com/windows/temp-environment-variable-has-a-2-or-other-number-after-it/
参考: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)
当组策略Do not use temporary folders per session
未配置或未设置为 Enabled 时,系统将生成两个 Volatile Environment 变量TEMP
&TMP
与当前用户TEMP
变量的值相同,并在 TEMP 文件夹的末尾添加一个增量数字(增量每次用户登录时,查看@Damien 的答案以获取详细信息)
If you set the group policy Do not use temporary folders per session
to enabled, this behavior will not occur.
如果您将组策略设置Do not use temporary folders per session
为启用,则不会发生此行为。