1

我使用的是 environ("username"),然后移至:

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

但我希望能够检查域是什么,如果它是一个实际的域或只是一个本地机器名称等......这可能吗?

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

4

1 回答 1

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

一个例子可以在这里找到

于 2012-09-10T18:00:26.970 回答