"Adam Parkin" <sk****@dfaslk.com> wrote in message news:<9BWjc.40469$NG2.1048@edtnps84>...
I was wondering, what's the "proper" (hehe) way to retrieve the system's
temp directory in VB 6.
Like for example, on my Windows XP machine the temp directory that is used
by programs for their temporary files is "C:\Documents And
Settings\MyUserName\Local Settings\Temp". Somehow those programs must look
up that value, and I'd like to do the same for my VB program.
Now I know I can look this up in the registry under
HKEY_CURRENT_USER\Environment, but I have no way of knowing if this
technique would be specific to WinXP.
Is there a Win32 API call that retrieves the temp folder? Or perhaps a way
of reading the "TMP" or "TEMP" environment variables?
Environ$("temp")
Environ$("tmp")
Private Declare Function GetTempPath Lib "kernel32" Alias
"GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal
lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Public Function TempFile() As String
' return temporary file name or empty string if error
Dim sDir As String
Dim sBuff As String
Dim x As Long
sBuff = Space$(512)
sDir = Space$(512)
x = GetTempPath(Len(sDir), sDir)
x = GetTempFileName(sDir, "TMP", 0, sBuff)
x = InStr(sBuff, vbNullChar)
If x > 0 Then
TempFile = Left(sBuff, x - 1)
Else
TempFile = ""
End If
End Function