取得Window, System, Temp所在目录

来源:cww

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
        "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
        ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
        "GetSystemDirectoryA" (ByVal lpBuffer As String, _
        ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
        (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub Command1_Click()
Dim WinPath As String, SysPath As String
Dim tempPath As String
Dim len5 As Long
'取得Windows 的目录
WinPath = String(255, 0)
len5 = GetWindowsDirectory(WinPath, 256)
WinPath = Left(WinPath, InStr(1, WinPath, Chr(0)) - 1)
Debug.Print "Window Path = "; WinPath

'取得Windows System的目录
SysPath = String(255, 0)
len5 = GetSystemDirectory(SysPath, 256)
SysPath = Left(SysPath, InStr(1, SysPath, Chr(0)) - 1)
Debug.Print "System Path : "; SysPath

'取得Temp的Directory
tempPath = String(255, 0)
len5 = GetTempPath(256, tempPath)
tempPath = Left(tempPath, len5)
Debug.Print "TEMP Path :"; tempPath
End Sub