views:

575

answers:

6

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,

A: 
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

Ismail
This still seems to be returning "my" temp dir. Rather than the system dir. e.g. on WinXP I'm looking to get "C:\WINSOWS\Temp" and not my own temp dir.
Mike
Is "windir" consistent across other OS's? Will services run on Server2008 still use %winddir%\Temp ?
Mike
You can also use "systemroot" instead of "windir". These all are Environment variables by default in the system and as far as I think, this should not change with new versions of windows, otherwise on upgrading the server all the previous installed applications (which uses these environment variables) will fail.
Ismail
Whatever, let me mention it clearly here, that I don't know if temp folder for services resides at "%windir%\temp" or "%systemroot%\temp" for Server 2008 or not. I think anyone can having sever 2008 installed can help us by trying %systemroot%\temp in run window and let us know.
Ismail
A: 

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

DRapp
In C# I prefer using: Path.GetTempPath()
Mike
Yes, however, something like this will expose to others a larger group of elements they might not have otherwise known were there. The System.Environment area has a lot of stuff available in it.
DRapp
I think solution is required in vbscript.
Ismail
A: 

This may be of interest: http://msdn.microsoft.com/en-us/library/bb774096%28VS.85%29.aspx

Remou
A: 

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.

ChristianLinnell
A: 

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

Mike
A: 

System.IO.Path.GetTempPath();

Debjit