I have a Windows service which need the currently logged username. I tried System.Environment.UserName
, Windows identity and Windows form authentication, but all are returning "System" as the user as my service is running in system privileged. Is there a way to get the currently logged in username without changing my service account type?
WindowsIdentity. GetCurrent(). Name; But, it is giving the output "NT AUTHORITY\SYSTEM " as the current user name after deploying the service.
User property in ASP.Net MVC Razor. In this article I will explain with an example, how to display Welcome Username after Login in ASP.Net MVC Razor. The Login Form will be implemented using Forms Authentication and Entity Framework and the Username will be displayed using the HttpContext.
This is a WMI query to get the user name:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem"); ManagementObjectCollection collection = searcher.Get(); string username = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
You will need to add System.Management
under References manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With