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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thephatp
    New Member
    • Mar 2008
    • 3

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

    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.Wind owsIdentity.Get Current().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\SYSTE M`.

    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.

    Chad
Working...