声明: Public Const MAX_PATH = 260 Public 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 Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long '代码: Public Function GetTempFile() As String Dim lngRet As Long Dim strBuffer As String, strTempPath As String '初始化 buffer strBuffer = String$(MAX_PATH, 0) '取得临时路径 lngRet = GetTempPath(Len(strBuffer), strBuffer) '0 错误 If lngRet = 0 Then Exit Function '去掉尾中的 null strTempPath = Left$(strBuffer, lngRet) '初始化 buffer strBuffer = String$(MAX_PATH, 0) '取得临时文件名 lngRet = GetTempFileName(strTempPath, "tmp", 0&, strBuffer) If lngRet = 0 Then Exit Function lngRet = InStr(1, strBuffer, Chr(0)) If lngRet > 0 Then GetTempFile = Left$(strBuffer, lngRet - 1) Else GetTempFile = strBuffer End If End Function If sTemp = "" Then 'Error 52 - Bad File Name or Number GetLongFilename = "" Exit Function End If sLongName = sLongName & "\" & sTemp iSlashPos = InStr(iSlashPos + 1, sShortName, "\") Wend 'Prefix with the drive letter GetLongFilename = Left$(sShortName, 2) & sLongName End Function