How to get the Windows Username/login

Hi all

Any Idea how to get the windows login/username property in C#/.NET environment

thanks




Answer this question

How to get the Windows Username/login

  • Ernst Kuschke

    > Try System.Threading.CurrentPrincipal.Identity.Name.
    By default Thread.CurrentPrincipal.Identity.Name that will just return an empty string, unless you have previously set Thread.CurrentPrincipal to a WindowsPrincipal.

    The previous response is right: use WindowsIdentity.GetCurrent().Name;


  • JBinGA

    Try System.Threading.CurrentPrincipal.Identity.Name.

    Bruce Johnson [C# MVP]
    http://www.objectsharp.com/blogs/bruce


  • Dorkboy

    Hi,

    I just got the solution from:

    System.Security.Principal.WindowsIdentity.GetCurrent().Name;

    I guess I can work from there :)

    cheers



  • How to get the Windows Username/login