获取系统临时文件夹?
I'm looking for something similar to this question. However, I am looking specifically to dynamically find the location of the system's temp folder (i.e. the temp folder used by services.)
Is this possible?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在这里(在 VBS 中)
我不确定您的系统是否有一个名为“TEMP”的环境变量,因此转到命令行并键入
您将获得环境变量及其值的列表。选择其中包含您的临时文件夹的那个。
Here you go (in VBS)
I'm not sure if your system will have an environment variable called "TEMP", so go to the command line and type
You'll get a list of environment vars, and their values. Pick the one that has your temp folder in it.
在这种情况下
希望这会有所帮助
In that case
hope this will help
经过一番研究后,我相信没有办法使用环境变量来捕获另一个用户的 %TEMP% 文件夹(在本例中为系统用户)的位置。
After researching a little into this, I believe there is no way to use environment variables to capture the location of another user's %TEMP% folder (in this case the System user).
SYSTEM 环境变量存储在注册表项中: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment
用户的环境变量存储在注册表项中: HKEY_USERS[user SID]\Environment
为了获取任何环境变量的值(特别是 TEMP),需要检查指定用户的分支中是否存在此变量。如果它在那里,那么您就可以使用它。如果不存在,则需要从系统注册表分支中获取值。
The SYSTEM environment variables is stored in registry key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment
The environment variables for users is stored in registry keys: HKEY_USERS[user SID]\Environment
In order to get the value of any environment variable (in particular TEMP), need to check the presence of this variable in the branch for specified the user. If it is there, then you can use it. If it is not there, then you need to take a value from the system registry branch.
在 C# 中,它...
System.Collections.IDictionary Vars = System.Environment.GetEnvironmentVariables();
字符串 TempPath = Vars["TEMP"];
您将获得完整的元素数组... Path、Temp、SessionName、PathExt、UserDomain、SystemDrive、WinDir 等...
In C#, its...
System.Collections.IDictionary Vars = System.Environment.GetEnvironmentVariables();
String TempPath = Vars["TEMP"];
You get an entire array of elements... Path, Temp, SessionName, PathExt, UserDomain, SystemDrive, WinDir, etc...
也许这可能有用: System.IO。 Path.GetTempPath()
Maybe this may be of some use: System.IO.Path.GetTempPath()