Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

Users in a domain

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vayse - 26 Apr 2007 15:59 GMT
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
Newbie Coder - 27 Apr 2007 21:52 GMT
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

Signature

Newbie Coder
(It's just a name)

> 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
[quoted text clipped - 6 lines]
> Thanks
> Vayse
Vayse - 30 Apr 2007 12:15 GMT
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

> Vayse,
>
[quoted text clipped - 50 lines]
>> Thanks
>> Vayse

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.