VB如何获取系统临时文件夹目录
一般是  C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files如何获取每台电脑的这个目录?

解决方案 »

  1.   

    Win 2K 或更高版本Windows系统、获得当前用户的 Internet临时文件夹 路径:Dim strInTmp$strInTmp = Environ("APPDATA") & "\Temporary Internet Files"
    MsgBox strInTmp, 64, "Internet临时文件夹路径"
      

  2.   

    窗体--
    Private Sub OpenDir(CSIDL As Long)
    Dim str As String
    str = GetSpecialPath(Me.hwnd, CSIDL) & "\"
    MsgBox str
    ShellExecute Me.hwnd, "open", str, vbNullString, vbNullString, SW_SHOWNORMAL
    End SubPrivate Sub Form_Load()
    OpenDir CSIDL_INTERNET_CACHE
    End Sub
    模块-----
    Public Const CSIDL_INTERNET_CACHE As Long = &H20
    Private Declare Function SHGetPathFromIDList _
            Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
            (ByVal pidl As Long, _
            ByVal pszPath As String) As LongPrivate Declare Function SHGetSpecialFolderLocation _
            Lib "shell32.dll" _
            (ByVal hwndOwner As Long, _
            ByVal nFolder As Long, _
            pidl As Long) As Long
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Public Const SW_SHOWNORMAL = 1   
    Public Function GetSpecialPath(hwnd, CSIDL As Long) As String '获得windows特殊文件夹路径的自定义函数
        Dim r As Long
        Dim path As String
        Dim pidl As Long
       
        '根据指定的文件夹获得pidl
        r = SHGetSpecialFolderLocation(hwnd, CSIDL, pidl)
       
        If r = NOERROR Then
            path = Space$(512)
            r = SHGetPathFromIDList(ByVal pidl, ByVal path)
            GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1)
            Exit Function
        End If    GetSpecialPath = ""
        '也可以这样写(本质上是一样的):
        'If r = NOERROR Then
           ' path = Space$(512)
            'r = SHGetPathFromIDList(ByVal pidl, ByVal path)
            'GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1)
        'else
        'GetSpecialPath = ""
        'End If
    End Function