Results 1 to 2 of 2

Thread: How can I get all Users from one Domain in a ListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Germany
    Posts
    15

    Question

    Can anyone help me with any API I can make this.
    Or have anyone a sample for NetUserEnum.

    VB 6 Enterprise Edition SP4

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    60

    Cool Solution

    You need to use the NetUserEnum api call, i have attached a function and the relevate declarations required for it, all you need to do is input the servername and the listbox where you want the usernames. You will have to get a list of servers (machines) in the domain before calling this function, if you need help with that just ask.

    'Module Code

    Public Const FILTER_NORMAL_ACCOUNT = &H2

    Public Type MungeLong
    X As Long
    Dummy As Integer
    End Type

    Public Type MungeInt
    XLo As Integer
    XHi As Integer
    Dummy As Integer
    End Type

    Public Declare Function NetUserEnum0 Lib "NETAPI32.DLL" Alias "NetUserEnum" (ServerName As Byte, ByVal Level As Long, ByVal lFilter As Long, Buffer As Long, ByVal PrefMaxLen As Long, EntriesRead As Long, TotalEntries As Long, ResumeHandle As Long) As Long
    Public Declare Function PtrToInt Lib "kernel32" Alias "lstrcpynW" (RetVal As Any, ByVal Ptr As Long, ByVal nCharCount As Long) As Long
    Public Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyW" (RetVal As Byte, ByVal Ptr As Long) As Long
    Public Declare Function StrLen Lib "kernel32" Alias "lstrlenW" (ByVal Ptr As Long) As Long
    Public Declare Function NetAPIBufferFree Lib "NETAPI32.DLL" Alias "NetApiBufferFree" (ByVal Ptr As Long) As Long

    Public Function EnumerateUsers(ByVal SName As String, lstCtrl As ListBox) As Long

    Dim Result As Long, BufPtr, EntriesRead, TotalEntries As Long
    Dim ResumeHandle, BufLen As Long
    Dim SNArray(), GNArray(), UNArray(99) As Byte
    Dim Uname As String, I As Integer, UNPtr As Long, TempPtr As MungeLong, TempStr As MungeInt

    SNArray = SName & vbNullChar
    GNArray = GName & vbNullChar

    BufLen = 255
    ResumeHandle = 0

    'Enumerate all users on the given server
    Result = NetUserEnum0(SNArray(0), 0, FILTER_NORMAL_ACCOUNT, BufPtr, BufLen, EntriesRead, TotalEntries, ResumeHandle)

    'Set the return of this function to the return of the API call function
    EnumerateUsers = Result

    'If an error occured during the api call exit the function
    If Result <> 0 And Result <> 234 Then
    Exit Function
    End If

    'Loop through all entries returned by the API call and retrieve the string of the username
    For I = 1 To EntriesRead
    Result = PtrToInt(TempStr.XLo, BufPtr + (I - 1) * 4, 2)
    Result = PtrToInt(TempStr.XHi, BufPtr + (I - 1) * 4 + 2, 2)

    LSet TempPtr = TempStr
    Result = PtrToStr(UNArray(0), TempPtr.X)
    Uname = Left(UNArray, StrLen(TempPtr.X))
    UserNames(I) = Uname
    Next I

    Result = NetAPIBufferFree(BufPtr)

    For a = 1 To EntriesRead
    'Add entries to the specified listbox
    lstCtrl.AddItem UserNames(a)
    Next a

    End Function



    Hope this helps you
    Grant French
    -----------------------------------------------
    E-Mail: [email protected]
    ICQ: 33122184

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width