什么决定了 Path.GetTempPath() 的返回值? [英] What determines the return value of Path.GetTempPath()?

查看:41
本文介绍了什么决定了 Path.GetTempPath() 的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我使用 Path.GetTempPath() 来确定写入日志文件的位置,但最近我遇到了一个用户的机器,其中返回的路径不是我所期望的.

Currently, I use Path.GetTempPath() to figure out where to write my log files, but recently I came across a user's machine where the path returned was not what I expected.

通常返回的路径是C:Documents and Settings[userid]Local SettingsTemp但在这种情况下,它是 C:Temp

Usually, the returned path is C:Documents and Settings[userid]Local SettingsTemp but in this case, it was C:Temp

这通常不是问题,但由于某种原因,相关用户无权写入 C:Temp

This would not normally be a problem, but for some reason the user in question did not have access to write to C:Temp

我仔细检查了环境变量,USER 环境变量按预期指向 C:Documents and Settings[userid]Local SettingsTemp,而 SYSTEM 环境变量指向到 C:WINNTTemp.

I double checked the environment variables, and the USER environment variable was pointing as expected to C:Documents and Settings[userid]Local SettingsTemp, whilst the SYSTEM environment variable was pointing to C:WINNTTemp.

那么... Path.GetTempPath() 从哪里获得它的价值?组策略?注册表?

So... where is Path.GetTempPath() getting it's value from ? Group Policy? Registry?

我用谷歌搜索过,但无济于事.

I have Googled, but to no avail.

推荐答案

(使用Reflector) Path.GetTempPath() 最终调用Win32函数GetTempPath(来自 kernel32.dll).该州的 MDSN 文档:

(Using Reflector) Path.GetTempPath() ultimately calls the Win32 function GetTempPath (from kernel32.dll). The MDSN docs for this state:

GetTempPath 函数按以下顺序检查环境变量是否存在,并使用找到的第一个路径:

The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

  • TMP 环境变量指定的路径.
  • TEMP 环境变量指定的路径.
  • USERPROFILE 环境变量指定的路径.
  • Windows 目录.

请注意,他们还声明 它不会检查路径是否实际存在或是否可以写入,因此您最终可能会尝试将日志文件写入不'不存在,或者您无法访问.

Note that they also state that it doesn't check whether or not the path actually exists or can be written to, so you may end up trying to write your log files to a path that doesn't exist, or one that you cannot access.

这篇关于什么决定了 Path.GetTempPath() 的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆