Users in a domain

  • Thread starter Thread starter Vayse
  • Start date Start date
V

Vayse

1) How do I get a list of all users in a domain?
I've searched the web, but any sample I've found seems to use VB 2003 or
earlier. Is there any samples that user 2005, and make full use of the My
functions?

2) In general, does getting a list of all the users require admin
permission?

Thanks
Vayse
 
Vayse,

Imports System.DirectoryServices

Private Sub LoadAllUsers()
'This will list all users in the Domain

Dim strDirEntryPath As String = "WinNT://" & MyDomain & "/" &
MyServer & "/" & "Domain Users" & ",group"

Dim group As New DirectoryEntry(strDirEntryPath)
Dim users As Object
users = group.Invoke("members")
Dim user1 As Object

'Datatable just used for sorting
Dim DT As New DataTable

Dim DC As New DataColumn("users")
DT.Columns.Add(DC)

Dim r1 As DataRow
Dim StrName As String

'Add each user to the data table
For Each user1 In CType(users, IEnumerable)
r1 = DT.NewRow
Dim userEntry As New
System.DirectoryServices.DirectoryEntry(user1)
r1.Item(0) = userEntry.Name
DT.Rows.Add(r1)
Next

'Use Data View to Sort Articles
Dim DV As New DataView(DT)
DV.Sort = "users asc"

Dim intCount As Integer = 0

For intCount = 0 To DV.Count - 1
Me.cboUsers.Items.Add(DV.Item(intCount).Row.Item(0))
Next
End Sub
 
Thanks. This is failing for me, with an unknown error, on
users = group.Invoke("members")

I suspect I may have strDirEntryPath incorrect. Are "WinNT" and "Domain
Users" always part of the string?
If not, how would I find what should have instead?
Thanks
Vayse
 
Back
Top