By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,553 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,553 IT Pros & Developers. It's quick & easy.

Handle the Windows Lock Desktop event/message?

P: n/a
Anybody out there know how I could go about handling, in a systray'd
app, the windows message that the desktop is going to be locked? This
way the application can react whenever the Win+L or Ctrl+Alt+Del+L is
used to lock the computer. I realize this will probably involve some
Windows API work, and am aware of the LockWorkStation inside the
User32.dll which causes the locking of the computer, but don't know
where to start to find out how to get that message from the API when my
form does NOT have focus. I imagine it will involve a Hook to the OS
somehow, but don't want to just hook the Win+L combo or just the
Ctrl+Alt+Del+L or any other way it locks, so would rather grab the
event.

Thanks!

Jan 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

An option would be to

a. Write your own GINA
b. Use the GINA hooks in the Platform SDK

Have a look at:
http://msdn.microsoft.com/msdnmag/is...ecurityBriefs/

Maybe that will get you going in the right direction

Jan 14 '06 #2

P: n/a
Anybody out there know how I could go about handling, in a systray'd
app, the windows message that the desktop is going to be locked?


Check out the WTSRegisterSessionNotification API.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 14 '06 #3

P: n/a

<br*****@bc3tech.net> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
| Anybody out there know how I could go about handling, in a systray'd
| app, the windows message that the desktop is going to be locked? This
| way the application can react whenever the Win+L or Ctrl+Alt+Del+L is
| used to lock the computer. I realize this will probably involve some
| Windows API work, and am aware of the LockWorkStation inside the
| User32.dll which causes the locking of the computer, but don't know
| where to start to find out how to get that message from the API when my
| form does NOT have focus. I imagine it will involve a Hook to the OS
| somehow, but don't want to just hook the Win+L combo or just the
| Ctrl+Alt+Del+L or any other way it locks, so would rather grab the
| event.
|
| Thanks!
|

When running on W2K or higher using framework v2.0, you could set-up a
listener for SystemEvents notifications.
Please check the Microsoft.Win32.SystemEvents SessionSwitchEventHandler for
details.

....
SystemEvents.SessionSwitch += new
SessionSwitchEventHandler (SystemEvents_SessionSwitch);
....
// unhook static eventhandler when application terminates!!!
....
//Handle event
static void SystemEvents_SessionSwitch(object sender,
SessionSwitchEventArgs e)
{
Console.WriteLine("The session is switched. Reason={0}", e.Reason);
}

Willy.
Jan 14 '06 #4

P: n/a
Awesome solution Willy! I had no idea that .net 2.0 had this
built-in... definitely a bit easier than working with APIs. I
implemented this solution in about 4.6 seconds ;)

Thanks again!

Jan 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.