office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

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

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

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

分享