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

查看:2391
本文介绍了是什么决定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和Settings\ [用户​​ID] \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

我仔细检查了环境变量和用户环境变量指着预期为 C:\Documents和Settings\ [用户​​ID] \Local Settings\Temp ,而系统环境变量指向的 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?

我用Google搜索,但没有效果。

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