How to get the current logged in user?
I already tried
Environment.CurrentUser
and
WindowsIdentity.GetCurrent().
Both of them return the user that is running the programm.
Thanks for your help.
Kind Regards, Sandro
How to get the current logged in user?
I already tried
Environment.CurrentUser
and
WindowsIdentity.GetCurrent().
Both of them return the user that is running the programm.
Thanks for your help.
Kind Regards, Sandro
Add the directive System.Management
.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
string username = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
Alternatively check out this accepted answer.