NT Domain User List 
Author Message
 NT Domain User List

Is there a way to get a list of Users from an NT Domain to populate a
combo box ona  form.

TIA,
Spencer



Fri, 21 Jun 2002 03:00:00 GMT  
 NT Domain User List
you can use the NetUserEnum api with user_info0 struct. Here's a VBA
conversion of the sample c++ code in platform SDK.

' ******** Code Start ********
Private Type USER_INFO_0
  usri0_name As Long
End Type

Private Declare Function apiNetUserEnum _
    Lib "netapi32.DLL" Alias "NetUserEnum" _
    (ByVal servername As Long, _
    ByVal level As Long, _
    ByVal filter As Long, _
    bufptr As Long, _
    ByVal prefmaxlen As Long, _
    entriesread As Long, _
    totalentries As Long, _
    resume_handle As Long) _
    As Long

Private Declare Function apiNetAPIBufferFree _
    Lib "netapi32.DLL" Alias "NetApiBufferFree" _
    (ByVal buffer As Long) _
    As Long

Private Declare Function apilstrlenW _
    Lib "kernel32" Alias "lstrlenW" _
    (ByVal lpString As Long) _
    As Long

Private Declare Sub sapiCopyMem _
    Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)

Private Const FILTER_TEMP_DUPLICATE_ACCOUNT = &H1&
Private Const FILTER_NORMAL_ACCOUNT = &H2&
Private Const FILTER_INTERDOMAIN_TRUST_ACCOUNT = &H8&
Private Const FILTER_WORKSTATION_TRUST_ACCOUNT = &H10&
Private Const FILTER_SERVER_TRUST_ACCOUNT = &H20&
Private Const MAX_PREFERRED_LENGTH = -1&
Private Const NERR_SUCCESS = 0
Private Const ERROR_MORE_DATA = 234&

Function fEnumDomainUsers( _
        ByVal strServerName As String) _
        As Boolean
' if strServerName=vbNullString,
' assume local machine
' This code only enums global accounts
'
On Error GoTo ErrHandler
Dim abytServerName() As Byte
Dim pBuf As Long
Dim pTmpBuf As USER_INFO_0
Dim dwLevel As Long
Dim dwPrefMaxLen As Long
Dim dwEntriesRead As Long
Dim dwTotalEntries As Long
Dim dwResumeHandle As Long
Dim i As Long
Dim dwTotalCount As Long
Dim nStatus As Long
Dim szName As String

    ' assume MAX_PREFERRED_LENGTH
    dwPrefMaxLen = MAX_PREFERRED_LENGTH
    abytServerName = strServerName & vbNullChar
    dwLevel = 0
    Do
        'only global users
        nStatus = apiNetUserEnum(VarPtr(abytServerName(0)), _
                            dwLevel, _
                            FILTER_NORMAL_ACCOUNT, _
                            pBuf, _
                            dwPrefMaxLen, _
                            dwEntriesRead, _
                            dwTotalEntries, _
                            dwResumeHandle)
        '// If the call succeeds,
        If ((nStatus = NERR_SUCCESS) Or (nStatus = ERROR_MORE_DATA)) Then
            '// Loop through the entries.
            For i = 0 To dwEntriesRead - 1
                Call sapiCopyMem(pTmpBuf, ByVal (pBuf + (i * 4)),
Len(pTmpBuf))
               '//  Print the name of the user account.
               szName = String$(apilstrlenW(pTmpBuf.usri0_name) * 2,
vbNullChar)
               Call sapiCopyMem(ByVal szName, ByVal pTmpBuf.usri0_name,
Len(szName))
               Debug.Print StrConv(szName, vbFromUnicode)
               dwTotalCount = dwTotalCount + 1
            Next
        End If
        Call apiNetAPIBufferFree(pBuf)
        pBuf = 0
    Loop While (nStatus = ERROR_MORE_DATA)
    If Not (pBuf = 0) Then Call apiNetAPIBufferFree(pBuf)

    fEnumDomainUsers = True
ExitHere:
    Exit Function
ErrHandler:
    fEnumDomainUsers = False
    Resume ExitHere
End Function
' ********* Code End ***********


Quote:
> Is there a way to get a list of Users from an NT Domain to populate a
> combo box ona  form.

> TIA,
> Spencer



Sat, 22 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. getting nt domain user list from VB5/6

2. NT Domain User List

3. NT domain users list

4. List of NT Users ina domain from running an application on an NT Client

5. User list from NT Domain - HELP

6. how to access user list of a NT domain

7. Get User List from NT Domain

8. List of NT Domain Users

9. List of NT Domain Users

10. List of NT Domain Users

11. COM Adding a user(account) on the nt database(user domain)

12. Getting full list of Domain Users is not working properly - some users missing

 

 
Powered by phpBB® Forum Software