How get the account of the user who login the window

eg.
I use this account "Abill" to login window, and then how to get it with C#

thank you.


Answer this question

How get the account of the user who login the window

  • tikki

    Hi,
    You can get this property :

    System.Security.Principal.WindowsIdentity currentUser = System.Security.Principal.WindowsIdentity.GetCurrent();

    //Show user's information
    userIdentityTextBox.Text = currentUser.Name;



  • DIII

    Quote from gwapo: You can also use Environment.UserName property.

    That's a very very bad idea as the process starting your app can override the environment tricking your application into thinking somebody else is using it.




  • dundret

    Hi,

    You can also use Environment.UserName property.


    Regards,

    -chris



  • stefandemetz

    Thanks BeckKhiem .

  • How get the account of the user who login the window