WindowsIdentity

  • Thread starter Thread starter Derek Martin
  • Start date Start date
D

Derek Martin

Does anyone know how to get the current logged on NAME from AD? I can get
the username domain\username, but I would like to actually get John W. Doe
from the currently logged in person. Anyone? Help? hehe

Derek
 
¤ Does anyone know how to get the current logged on NAME from AD? I can get
¤ the username domain\username, but I would like to actually get John W. Doe
¤ from the currently logged in person. Anyone? Help? hehe

There are several ways to do this but using the NT provider (instead of LDAP) is probably the
easiest:

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

Dim FullName as String = ADEntry.Properties("FullName").Value


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Wonderful! Thank you Paul, is there a way to use what you just gave me to
retrieve the user's group membership?

For instance, something like:
dim mygroups as something = adentry.properties("memberOf").something

???

Thank you!

Derek
 
¤ Wonderful! Thank you Paul, is there a way to use what you just gave me to
¤ retrieve the user's group membership?
¤
¤ For instance, something like:
¤ dim mygroups as something = adentry.properties("memberOf").something

You can grab the list of groups in which the user is a member using the WinNT provider:

Dim ADGroups As Object
Dim ADGroup As Object

Dim DomainUser As String =
System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")

Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

ADGroups = ADEntry.Invoke("Groups")

For Each ADGroup In ADGroups
Console.WriteLine(ADGroup.Name)
Next


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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

Back
Top