C# Active Directory Get current user logged into Windows

Hello Expert, I was wondering if you could help me with code that will Get the current user logged into Windows Active Directory I am using a C# Windows Form. I just need to get the user name of who is on the pc at this time.
Thanks
jvoros1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
esteban_felipeConnect With a Mentor Commented:
jvoros1,

you need to add System.Security.Principal namespace to your code

using System.Security.Principal;

Esteban Felipe
www.estebanf.com
0
 
esteban_felipeCommented:
Hi jvoros1,

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
String username = wp.Identity.Name;


Esteban Felipe
www.estebanf.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.