Option Explicit
Public Const MAX_PATH = 260
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Sub GetSystemDirectory_test()
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)
MsgBox "Windows System 路径=" & S, , "GetSystemDirectory"
End Sub
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function WinDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetWindowsDirectory(S, Z)
WinDir = Left(S, R)
WinDir = WinDir & "\"
End Function
Public Function SysDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetSystemDirectory(S, Z)
SysDir = Left(S, R)
SysDir = SysDir & "\"
End Function
Public Function TempDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetTempPath(Z, S)
TempDir = Left(S, R)
End Function
Public Function UserName() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetUserName(S, Z)
UserName = S
End Function
Public Function ComputerName() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetComputerName(S, Z)
ComputerName = S
End Function