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:


    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?


    Tuesday, March 30, 2010 9:35 PM


All replies