Saturday, June 19, 2010

Determine Logged-In User

To determine, which user is currently logged in, is also no problem with the extensive .Net library.
The easiest way is via the class Environment:
string UserName = Environment.UserName;
The following command also reaches this goal, the containing class accesses the system a little more deeply and has interesting other uses, one of which I will show in the next post:
string UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

No comments:

Post a Comment