Kevin said:
Hi,
I need to trap when a workstation is locked. I saw this article
http://msdn.microsoft.com/library/d...n/security/winlogon_notification_packages.asp,
but i don't understand how to do an event handler of Winlogon Notification
Events. Also I saw the "WlNotify.dll" but either understand how to use it.
Somebody can help me? :$
Thanks
When running on XP or higher you can register for session change
notifications by calling (through PInvoke) TS API
"WTSRegisterSessionNotification", note that you need a Windows procedure to
capture the messages .
Here are the PInvoke declarations..
[DllImport("wtsapi32.dll")]
private static extern bool WTSRegisterSessionNotification(IntPtr hWnd,
int dwFlags);
[DllImport("wtsapi32.dll")]
private static extern bool WTSUnRegisterSessionNotification(IntPtr
hWnd);
and how to register,
private const int NotifyForThisSession = 0; // This session only
WTSRegisterSessionNotification(this.Handle, NotifyForThisSession);
and here the messages you can check..
private const int SessionChangeMessage = 0x02B1;
private const int SessionLockParam = 0x7;
private const int SessionUnlockParam = 0x8;
in your overriden WndProc.
protected override void WndProc(ref Message m)
{
// check for session change notifications
if(m.Msg == SessionChangeMessage)
{
if(m.WParam.ToInt32() == SessionLockParam)
OnSessionLock(); // Do something when locked
else if(m.WParam.ToInt32() == SessionUnlockParam)
OnSessionUnlock(); // Do something when unlocked
}
base.WndProc(ref m);
return;
}
void OnSessionLock() {...}
...
void OnSessionUnlock() {...}
call "WTSUnRegisterSessionNotification" when you no longer need to be
notified...
Willy.