I tried:
var curUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
But, it is giving the output "NT AUTHORITY\SYSTEM " as the current user name after deploying the service.
I tried:
var curUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
But, it is giving the output "NT AUTHORITY\SYSTEM " as the current user name after deploying the service.
If I understand your question correctly, you would like to retrieve the authenticated user on the Windows Machine from your Windows Service (is that correct)?
This will not work, because services doesn't run under a user, they are running under a given account, which can be user, but doesn't need to be.
Generally speaking, anything running as a service does not require a user to be logged in for the application(s) which depend on that service to be fully functional. Really, that's the entire bases of the Windows NT service model.
If you log on, do some work and then log off, all the processes which your logon session started will be shut down (eg: application executables, etc), but services will be unaffected.
The image below demonstrates where the running user is specified:
I know that this isn't an answer to your question, but I've posted this as an answer to be able to provide some description and images. I don't think there's a solution for what you're trying to achieve.