使用API穫取windows繫統路徑(System32)目録的函數

2017-07-22 22:41:00
zstmtony
原創
650

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

分享