获取系统目录和Windows目录
获取系统目录和Windows目录 有时我们需要让自己的程序判断系统目录和Windows目录的名字。这时可以调用WindowsAPI函数GetSystemDirectory和GetWindowsDirectory。
声明:
' 获取系统目录
Public Declare Function GetSystemDirectory Lib 'kernel32' Alias 'GetSystemDirectoryA' _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
' 获取Windows目录
Declare Function GetWindowsDirectory Lib 'kernel32' Alias 'GetWindowsDirectoryA' _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
调用:
' 检查系统目录
Public Function GetSystemPath() As String
Dim p As String * 80
Dim length As Long
Dim path As String
length = GetSystemDirectory(p, Len(p))
path = Left(p, length)
GetSystemPath = path
End Function
' 检查Windows目录
Public Function GetWindowsPath() As String
Dim p As String * 80
Dim length As Long
Dim path As String
length = GetWindowsDirectory(p, Len(p))
path = Left(p, length)
GetWindowsPath = path
End Function