Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello all,

i'm trying to get windoes %temp% value using ExpandEnvironmentString. but it can be redefined.
how to retrieve default %temp% value?
Posted
Updated 25-Jul-11 3:51am
v2
Comments
Albert Holguin 25-Jul-11 10:35am    
Environment variables are meant to be redefinable (hence the variable part of the name), if you need some path that cannot be redefined, then you shouldn't use environment variables.

What do you mean by default value?
The value that was before your program was run?
You cannot know it.
You will need to run a program that starts with Windows and record it.

I think you must use GetTempPath as Madhu said.

Here is what it returns according to the documentation -
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable.
3. The path specified by the USERPROFILE environment variable.
4. The Windows directory.
Note that the function does not verify that the path exists.
Symbolic link behavior—If the path points to a symbolic link, the temp path name maintains any symbolic links.
 
Share this answer
 
Comments
Richard MacCutchan 26-Jul-11 9:54am    
See my answer.
Look at the registry key HKEY_CURRENT_USER\Environment, and check the value of TMP and TEMP. If these values do not exist then you cannot be sure what the originals were.
 
Share this answer
 
Use API GetTempPath[^]
 
Share this answer
 
Comments
Richard MacCutchan 25-Jul-11 10:10am    
But this will only get the current version, which may not be the original when the user logged on.
Stephen Wiria 25-Jul-11 10:17am    
There's an interesting article and discussion from Raymond related to this: http://blogs.msdn.com/b/oldnewthing/archive/2011/06/20/10176772.aspx
The default name is always "c:\Windows\TEMP". (for NT, it was C:\WINNT\TEMP). Keep in mind that the only real variable here is the path to the Windows folder (if the user installed it somewhere otgher than drive C:.
 
Share this answer
 
Comments
Richard MacCutchan 25-Jul-11 10:09am    
Not true John, in Windows 7 it is %USERPROFILE%\AppData\Local\Temp
#realJSOP 25-Jul-11 17:28pm    
Check your windows folder.
Richard MacCutchan 26-Jul-11 9:54am    
That is not in dispute, it's the value of the environment variables that OP is asking about.
ASM
DWORD WINAPI GetTempPath(
  __in   DWORD nBufferLength,
  __out  LPTSTR lpBuffer
);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900