• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2356
  • Last Modified:

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

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
fcti
Asked:
fcti
  • 2
1 Solution
 
Anurag ThakurCommented:
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
 
fctiAuthor Commented:
Sorry Ragi, that solution won't apply, its for a Windows Application, not a Service.  It relies on WndProc.
0
 
fctiAuthor Commented:
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now