User listing in a domain (VB.NET 2005 - Windows XP)

G

Guest

I would like a listing of all users in the current domain (or on my
computer). I'm running Windows XP Home Edition and I've set up four user, one
for each member of my family.

'My.User.Name' just lists me. How do I get the others? I looked at some code
posted here on 4/27/07 and it doesn't work, I've already tried it.

Thanks in advance.
 
P

PlatinumBay

dmbuso,

Here is some Console code to grab all the users in the Administrators group
and display their name and SID. You can change the group name in the code.

Code:

Imports System.Security.Principal
Imports System.DirectoryServices

Module Module1
Sub Main()
Dim localMachine As New DirectoryEntry("WinNT://" &
Environment.MachineName)
Dim admGroup As DirectoryEntry =
localMachine.Children.Find("administrators", "group")
Dim members As Object = admGroup.Invoke("members", Nothing)
For Each groupMember As Object In CType(members, IEnumerable)
Dim member As New DirectoryEntry(groupMember)
Console.WriteLine(member.Name)

Dim si As New
SecurityIdentifier(CType(member.Properties("objectSid")(0), Byte()), 0)
Dim sid As String = si.Value
Console.WriteLine(sid)
Next

Console.ReadLine()
End Sub
End Module

Hope this helps,


Steve
 
G

Guest

Steve,

I wanted all user, not administrators. I will try your code and see if I can
modify it for all users.
 
W

Walter Wang [MSFT]

Hi Dave,

In that case, I think you can simply replace 'administrators' with 'users':

Dim admGroup As DirectoryEntry = localMachine.Children.Find("users",
"group")


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top