Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1337
  • Last Modified:

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
0
jvoros1
Asked:
jvoros1
  • 2
1 Solution
 
esteban_felipeCommented:
Hi jvoros1,

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


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

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

using System.Security.Principal;

Esteban Felipe
www.estebanf.com
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now