By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

How to Get Current logged in user from within a Windows Service

P: 3
Is there any possible way to get the currently logged in (active) user from within a service?

I need the service to start at runtime. I need to capture log on / log off / switch user events. I haven't gotten to that yet, but it IS possible from within a windows service, correct? I figured I'd ask because of my current problem.

Line of code in question:

System.Security.Principle.WindowsIdentity.GetCurre nt().Name

From within an application running locally, the output is <myLoginName>.
From within a Windows Service running locally in the background, the output is `NT AUTHORITY\SYSTEM`.

Is there any way to get the currently logged in and active user (in the case that multiple users are logged in, we only care about the active one) from code executing in a windows service??

Thanks in advance.

Mar 24 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.