获取系统临时文件夹?

发布于 2024-08-10 13:18:40 字数 197 浏览 3 评论 0原文

我正在寻找类似于这个问题的问题。但是,我正在专门寻找动态查找系统临时文件夹的位置(即服务使用的临时文件夹)。

这可能吗?

谢谢,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

找个人就嫁了吧 2024-08-17 13:18:40

在这里(在 VBS 中)

Set environmentVars = WScript.CreateObject("WScript.Shell").Environment("Process")
tempFolder = environmentVars("TEMP")
msgbox(tempFolder)

我不确定您的系统是否有一个名为“TEMP”的环境变量,因此转到命令行并键入

set

您将获得环境变量及其值的列表。选择其中包含您的临时文件夹的那个。

Here you go (in VBS)

Set environmentVars = WScript.CreateObject("WScript.Shell").Environment("Process")
tempFolder = environmentVars("TEMP")
msgbox(tempFolder)

I'm not sure if your system will have an environment variable called "TEMP", so go to the command line and type

set

You'll get a list of environment vars, and their values. Pick the one that has your temp folder in it.

一身骄傲 2024-08-17 13:18:40
Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("temp")
WScript.Echo objPath    

在这种情况下

Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("windir")
WScript.Echo objPath & "\temp"    

希望这会有所帮助

Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("temp")
WScript.Echo objPath    

In that case

Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("windir")
WScript.Echo objPath & "\temp"    

hope this will help

眼眸里的那抹悲凉 2024-08-17 13:18:40

经过一番研究后,我相信没有办法使用环境变量来捕获另一个用户的 %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).

老旧海报 2024-08-17 13:18:40

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.

羁客 2024-08-17 13:18:40

在 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...

谁许谁一生繁华 2024-08-17 13:18:40

也许这可能有用: System.IO。 Path.GetTempPath()

Maybe this may be of some use: System.IO.Path.GetTempPath()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文