views:

226

answers:

1

Hi Guys,

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

A: 

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;
Kyle Rozendo
Hi, the Enviroment.UserName simply returns the UserName for the current process, not the current Windows Logon. For Instance i have:* MyUserName - Logged in* MyAppUser - Running MyUserAppI need to get MyUserName, from MyUserApp. Without any special permissions for MyAppUser.