Reputation: 5998
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,
Upvotes: 2
Views: 12953
Reputation: 89
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.
Upvotes: 1
Reputation: 5998
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).
Upvotes: 1
Reputation: 1398
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.
Upvotes: 2
Reputation: 48139
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...
Upvotes: -1
Reputation: 10863
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
Upvotes: 1