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

查看:149
本文介绍了什么决定了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 Settings\Temp
,但在这种情况下,它是 C:\Temp

Usually, the returned path is C:\Documents and Settings\[userid]\Local Settings\Temp 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 Settings\Temp ,而SYSTEM环境变量指向 C:\WINNT\

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

所以...哪里是 Path.GetTempPath()获取它的价值?组策略?注册表?

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

我有谷歌,但无济于事。

I have Googled, but to no avail.

推荐答案

(使用反射器) 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目录。

  • The path specified by the TMP environment variable.
  • The path specified by the TEMP environment variable.
  • The path specified by the USERPROFILE environment variable.
  • The Windows directory.

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

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天全站免登陆