此函数返回当前登录的NT用户的用户名。
' This library must be declared
Declare Function GetUserName& _
Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String,
nSize As Long)
Function sys_OrigUserID() As String
Dim s$, cnt&, dl&
Dim max_String As Integer
Dim username As String
max_String = 30
cnt& = 199
s$ = String$(max_String, 1)
dl& = GetUserName(s$, cnt)
username = Trim$(Left$(s$, cnt))
username = UCase(Mid(username, 1, Len(username) - 1))
sys_OrigUserID = username
End Function
From: https://bytes.com/topic/access/insights/653928-function-return-username-nt-login-current-user