Getting the systems Temp Directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Parkin

    Getting the systems Temp Directory

    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:\Documen ts And
    Settings\MyUser Name\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_US ER\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?

    Thanks....


  • Randy Birch

    #2
    Re: Getting the systems Temp Directory

    Yes, the GetTempPath API will return it. See
    VBnet provides Intermediate and Advanced Win32 API code for VB developers. Comprehensive Code, FAQ, Developers Resources & News, alphabetical API/Type/Constant/Method Index, along with the largest Visual Basic-related links list on the net.


    --

    Randy Birch
    MVP Visual Basic

    Please respond only to the newsgroups so all can benefit.


    "Adam Parkin" <skdfja@dfaslk. com> wrote in message
    news:9BWjc.4046 9$NG2.1048@edtn ps84...
    : 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:\Documen ts And
    : Settings\MyUser Name\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_US ER\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?
    :
    : Thanks....
    :
    :

    Comment

    • Bob Butler

      #3
      Re: Getting the systems Temp Directory

      "Adam Parkin" <skdfja@dfaslk. com> wrote in message news:<9BWjc.404 69$NG2.1048@edt nps84>...[color=blue]
      > 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:\Documen ts And
      > Settings\MyUser Name\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_US ER\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?
      >[/color]

      Environ$("temp" )
      Environ$("tmp")

      Private Declare Function GetTempPath Lib "kernel32" Alias
      "GetTempPat hA" _
      (ByVal nBufferLength As Long, _
      ByVal lpBuffer As String) As Long
      Private Declare Function GetTempFileName Lib "kernel32" _
      Alias "GetTempFileNam eA" (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

      Comment

      • Adam Parkin

        #4
        Re: Getting the systems Temp Directory

        That was exactly what I was looking for, thanks!

        Adam

        "Randy Birch" <rgb_removethis @mvps.org> wrote in message
        news:SrYjc.3181 $x6K1.1957@news 01.bloor.is.net .cable.rogers.c om...[color=blue]
        > Yes, the GetTempPath API will return it. See
        > http://vbnet.mvps.org/code/system/windirs.htm
        >
        > --
        >
        > Randy Birch
        > MVP Visual Basic
        > http://vbnet.mvps.org/
        > Please respond only to the newsgroups so all can benefit.
        >
        >
        > "Adam Parkin" <skdfja@dfaslk. com> wrote in message
        > news:9BWjc.4046 9$NG2.1048@edtn ps84...
        > : 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[/color]
        used[color=blue]
        > : by programs for their temporary files is "C:\Documen ts And
        > : Settings\MyUser Name\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_US ER\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?
        > :
        > : Thanks....
        > :
        > :
        >[/color]


        Comment

        Working...