locked
Getting username from a session ID RRS feed

  • Question

  • I'm working on a .NET Service. I've implemented OnSessionChange to catch user logon and logoff. The SessionChangeDescription that it sent to OnSessionChange contains a reason (logon/logoff/lock etc) and a sessionId. I'm guessing I can use the sessionId to figure out the username, but I'm at a loss as to how.

    I found one example of how to do it:

    http://stackoverflow.com/questions/248186/service-needs-to-detect-if-workstation-is-locked-and-screen-saver-is-active

    But instantiating a WindowsIdentity using p.Handle as shown in the example code leads to:

    System.ArgumentException: Invalid token for impersonation - it cannot be duplicated.

    Any ideas?

    Cheers,
    Rickard

    Tuesday, March 30, 2010 9:35 PM

Answers

All replies