Answered by:
Getting username from a session ID

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,
RickardTuesday, March 30, 2010 9:35 PM
Answers
-
For future reference, the way I solved this was to use Cassia:
http://code.google.com/p/cassia/
Cassia is a .NET library for accessing the native Windows Terminal Services API.
- Proposed as answer by Bruno Coelho Marques Wednesday, March 31, 2010 12:37 PM
- Marked as answer by SamAgain Wednesday, April 7, 2010 10:41 AM
Wednesday, March 31, 2010 11:52 AM
All replies
-
Hi ,
Look at this link
http://forums.lhotka.net/forums/t/505.aspx
enmanuel f grullard almonte
Republica Dominicana
Nota:SI TE FUE UTIL ESTA INFORMACION MARCALA COMO VALIDA.
Tuesday, March 30, 2010 10:00 PM -
Hmm. Forgive me, but that did link have anything particular of interest to my case?
Tuesday, March 30, 2010 10:37 PM -
hi,
was sorry to someone else
Wednesday, March 31, 2010 11:45 AM -
For future reference, the way I solved this was to use Cassia:
http://code.google.com/p/cassia/
Cassia is a .NET library for accessing the native Windows Terminal Services API.
- Proposed as answer by Bruno Coelho Marques Wednesday, March 31, 2010 12:37 PM
- Marked as answer by SamAgain Wednesday, April 7, 2010 10:41 AM
Wednesday, March 31, 2010 11:52 AM