473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

WindowsIdentity

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

--
Derek Martin
593074
Nov 21 '05 #1
3 5054
On Fri, 17 Sep 2004 10:39:26 -0500, "Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote:

¤ 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.GetCurre nt.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

Dim FullName as String = ADEntry.Properties("FullName").Value
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #2
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
"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:0v********************************@4ax.com...
On Fri, 17 Sep 2004 10:39:26 -0500, "Derek Martin"
<dm*****@DONTSPAMMEokstateDOT.edu> wrote:

¤ 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.GetCurre nt.Name.Replace("\",
"/")
Dim ADEntry As New
System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)

Dim FullName as String = ADEntry.Properties("FullName").Value
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #3
On Fri, 17 Sep 2004 13:44:43 -0500, "Derek Martin" <dm*****@DONTSPAMMEokstateDOT.edu> wrote:

¤ 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.GetCurre nt.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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Phillips | last post by:
I periodically get an ApplicationException "access is denied" in the WindowsIdentity._GetCurrentToken() method. Reflector shows the _GetCurrentToken() method as private static extern IntPtr...
8
by: BLiTZWiNG | last post by:
After playing with the code shown and utilising Willy Denyottes' help, I have come to the conclusion that there is some form of difference between the managed WindowsIdentity.Impersonate() over the...
3
by: ZUP_DUDE | last post by:
I have a webservice that is using impersonation. The web service needs to call a System.Diagnostics.Process to execute a batch file. I am having problems executing the batch file. It works fine on...
3
by: diephouse | last post by:
I seem to be having a problem accessing networks shares. For example, I try the following code: File.Exists(@"\\SERVER\share"); always returns false! Or even if I map the drive ...
3
by: Kevin Burton | last post by:
This is more of a solution that raised a question. I have a Web service that does not allow anonymous users. For debugging I put in the following lines in my Web Service: WindowsIdentity wi =...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
13
by: ALI-R | last post by:
I know how to authenticate to a webservice using either of these ways(Assuming that rService represents the webservice): 1) rService.Credentials = new...
1
by: Roger | last post by:
I have a desktop and laptop for development. Both are xps and both are sp2 and both are update to date with security patches. On my desktop when I run the LogonUser api function call. It...
1
by: Raghu | last post by:
If a company has windows machines but the directory services is not active directory (say novell's eDirectory for whatever reason and users are authenticated against this non-AD directory...
0
by: Ed Sutton | last post by:
Is there a FileSecurity method that can determine if the current WindowsIdentity has write access to a file? I can get the current windows identity and use FileSecurity to return the ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.