使用API获取windows系统路径(System32)目录的函数

2017-07-22 22:41:00
zstmtony
原创
351

Access VBA 使用API获取windows系统路径(System32)目录的函数

(如果是windows  64位系统,则获取的是 64位的系统目录)


OptionExplicit
PublicConst MAX_PATH = 260
'作者:tmtony-Office中国
DeclareFunction GetSystemDirectory Lib "kernel32" Alias"GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long)As Long
Public Function MyGetSystemDirectory() as String
    Dim S As String, Length As Long
    S = String(MAX_PATH, 0)
    Length = GetSystemDirectory(S, MAX_PATH)
    S = Left(S, InStr(S, Chr(0)) - 1)
    MyGetSystemDirectory=S  'Windows System 系统路径 
End Sub

Sub Main()
    Msgbox MyGetSystemDirectory()
End Sub

如果是windows 64位,想获取 32位的系统目录呢。则可以参考这里

 http://www.office-cn.net/access-function/142.html

分享