Access / Excel中的用户安全性 - 检索域/机器名称

时间:2012-09-10 12:35:55

标签: excel vba ms-access

我正在使用environ(“用户名”),然后转到:

Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
    fOSUserName = Left$(strUserName, lngLen - 1)
Else
    fOSUserName = vbNullString
End If
End Function

但是我希望能够检查域名是什么,以及它是实际域还是本地机器名等等......这可能吗?

我已经讨论了有关设置域组/安全组等的问题,所以不需要输入这些谢谢。

1 个答案:

答案 0 :(得分:1)

好吧,Environ("USERDOMAIN")应该获取域名,但是如果你想使用api声明,那么你需要:

Private Declare Function LookupAccountName Lib "advapi32" Alias "LookupAccountNameA" (ByVal lpSystemName As String, _
    ByVal lpAccountName As String, Sid As Byte, cbSid As Long, ByVal DomainName As String, _
    cbDomainName As Long, peUse As Long) As Long

可以找到一个示例here