I'm running a .Net application as a service under a special application user. From this service, i would like to get the User Name running the currently logged in session.
I tried getting the user name that owns the Explorer.exe process, but the restricted user does not have access to this as it throws an exception if i try and get the process handle.
What other options are available?
Regards
Tris
Using System.Environment.UserName
will get you what you need, as well as domain if you like etc. A very very useful class.
EDIT:
Alright then, try this?
System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent();
string Name = user.Name;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.