Return NT Username

I am new to windows forms (asp.net developer), but I have a win application that I need to get the user's NT Authentication username

Can someone guide me to how this can be pulled

Thanks,

ScAndal


Answer this question

Return NT Username

  • Time Out

    A lot of times that information can be obtained in the registry if you can find it. Of course the path may change depending on OS, however if your application is limited the following would find it also. A registry search on a computer for its known name may also help find the path:

    Me.txtComputerName.Text = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", Nothing)



  • Les Peabody

    Also you can find the user name by using:

    textBox8.text=my.user.name



  • John Wion

    If you are only looking for the users UserName, you can get it the name by reading Environment.UserName, and the domain (if any) by calling Environment.UserDomainName.

    Should you require more information about the user, you can intargate the current thread for information using the same mechanisms you would in ASP.NET, the IIdentity (who) of the IPrincipal (account) that is running it:

    (requires using System.Threading; and using System.Security.Principal;)

                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
                IPrincipal principal = Thread.CurrentPrincipal;
                IIdentity identity = principal.Identity;
                Console.WriteLine(identity.Name);

    Here we are able to learn from the identity about the user account in use, if it is logged in and via what mechanism.

    The IPrincipal instance we used to determine this contains even more information on the rights of the account with the IsInRole() method.



  • Return NT Username