Solved

Capture Terminal Session Lock and Unlock events in C# Windows Service

Posted on 2008-10-15
3
2,242 Views
Last Modified: 2013-12-17
I need to create a Windows Service that will capture when a user locks and unlocks their desktop session.  Also, I need to capture the username.  I know how to do this using a regular application, just not a Windows Service.
0
Comment
Question by:fcti
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22727675
have a look at the following ee link - i think it might be helpful
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22518173.html
0
 

Author Comment

by:fcti
ID: 22727698
Sorry Ragi, that solution won't apply, its for a Windows Application, not a Service.  It relies on WndProc.
0
 

Accepted Solution

by:
fcti earned 0 total points
ID: 22735758
Found the solution.  I am overriding the following event in my service:


protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
switch (changeDescription.Reason)
            {
                case SessionChangeReason.SessionLogon:
                    //Logon
                    break;
                case SessionChangeReason.SessionLogoff:
                    //Logoff
                    break;
                case SessionChangeReason.RemoteConnect:
                    //Remote Connect
                    break;
                case SessionChangeReason.RemoteDisconnect:
                    //Remote Disconnect
                    break;
                case SessionChangeReason.SessionLock:
                    //lock
                    break;
                case SessionChangeReason.SessionUnlock:
                    //Unlock
                    break;
                default:
                    break;
            }
}

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question