GetTempPath2A function (fileapi.h)
Retrieves the path of the directory designated for temporary files, based on the privileges of the calling process.
DWORD GetTempPath2A( [in] DWORD BufferLength, [out] LPSTR Buffer );
The size of the string buffer identified by lpBuffer, in TCHARs.
A pointer to a string buffer that receives the null-terminated string specifying the temporary file path. The returned string ends with a backslash, for example, "C:\TEMP\".
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the length, in TCHARs, of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The maximum possible return value is MAX_PATH+1 (261).
When calling this function from a process running as SYSTEM it will return the path C:\Windows\SystemTemp, which is inaccessible to non-SYSTEM processes. For non-SYSTEM processes, GetTempPath2 will behave the same as GetTempPath.
The GetTempPath2 function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
Symbolic link behavior—If the path points to a symbolic link, the temp path name maintains any symbolic links.
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
|Server Message Block (SMB) 3.0 protocol||Yes|
|SMB 3.0 Transparent Failover (TFO)||Yes|
|SMB 3.0 with Scale-out File Shares (SO)||Yes|
|Cluster Shared Volume File System (CsvFS)||Yes|
|Resilient File System (ReFS)||Yes|
For an example, see Creating and Using a Temporary File.
The fileapi.h header defines GetTempPath2 as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
|Minimum supported client||Windows 10 Build 20348|
|Minimum supported server||Windows Server Build 20348|
|Header||fileapi.h (include Windows.h)|