Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the names of all users on NT machine

Status
Not open for further replies.

databasedemon2002

Programmer
Dec 18, 2002
6
US

Is there any way of accessing all the user names on a Win 2K machine? I know there is an API to return the user currently logged on.

Any help would be greatly appreciated.

Thanks!
 
Hi there,

Use This...
References - Active DS Type Library
Controls - Winsock, ComboBox, ListBox

Code:
Private Sub Form_Load()
 'Fill the combo with LocalHost and Domains names
    Combo1.AddItem Winsock1.LocalHostName
    Dim namespace As IADsContainer
    Dim domain As IADs
    Set namespace = GetObject("WinNT:")
    
    For Each domain In namespace
       Combo1.AddItem domain.Name
    Next
End Sub

Private Sub Combo1_Click()
  'Fill the list whith all users of the selected Domains or LocalHost
    On Error Resume Next
    List1.Clear
    
    Dim container As IADsContainer
    Dim containername As String
    containername = Combo1.Text
    Set container = GetObject("WinNT://" & containername)
    
    container.Filter = Array("User")
    Dim user As IADsUser
    For Each user In container
       List1.AddItem user.Name
    Next
    
    Err = 0
    DoEvents
End Sub

Enjoy....


 
Thanks for the tip! I haven't tried it but it looks good. However, since there is a reference for Active Directory Scripting, would this code only work on a Win2K domain server since only domain servers contain an Active Directory? If so, are there other techniques that could get user names on a machine without the Active Directory?

Thanks for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top