'代码出处:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763104687270e54f7327d818c027fa3cf1fd5791d1c053db2fa3a211407d2ce68225cef1f53aea02172461451b48cbe835dacc885582c9f2644676d865662d60edfbc5155c5&p=8f6f8d0486cc42af5caac32d021492&newp=8b2a971c99985ff72abd9b7d0d1283231610db2151d3d44c308f8d10e1&user=baidu&fm=sc&query=vb+%C1%D9%CA%B1%C2%B7%BE%B6&qid=b97945f7000035ea&p1=3
Private Declare Function GetTempPath Lib "KERNEL32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function GetWindowTempPath() As String
    Dim Dummy As Long, StrLen As Long, TempPath As String
    StrLen = 255
    TempPath = String$(StrLen, 0)
    Dummy = GetTempPath(StrLen, TempPath)
    If Dummy Then
        GetWindowTempPath = Left$(TempPath, Dummy)
    Else
        GetWindowTempPath = ""
    End If
End Function
Private Sub Form_Load()
    MsgBox GetWindowTempPath() '获取结果
End Sub