CodeItBetter Programming Another VB Programming Blog

How to Get windows temp path

Posted on July 13, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'System & API - How to Get windows temp path
Option Explicit
 
Private Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" _
   (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
 
Private Sub Command1_Click()
'Get Windows's temporary file directory.
   Dim TempPath As String  'receives name of temporary file path
   Dim StrLen As Long      'receives length of string returned for the path
   
'Get Windows's temporary file path
   TempPath = Space(255)            'initialize the buffer to receive the path
   StrLen = GetTempPath(255, TempPath) 'read the path name
   TempPath = Left(TempPath, StrLen)  'extract data from the variable
   
   MsgBox TempPath
End Sub
Comments (1) Trackbacks (0)
  1. It is so cool and easy but can we replace the “GetTempPathA” with another values to get other special folders in windows?
    if yes,what are those values?

    thanks :)


Leave a comment


 

No trackbacks yet.