473,287 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Handle the Windows Lock Desktop event/message?

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
4 21442

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
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

<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jjmraz | last post by:
Hi, How can I lock down the desktop stopping end user from getting to desktop when inside my app until they quit app? Also how can I start another app from my app? Thanks, JJ
3
by: aspirit | last post by:
hello Is it possible (and how) to enum all windows on desktop in c# ? I need this to write a program which closes miscelanious windows with various titles.
3
by: suvarnask1 | last post by:
Any one can help MEEEE .....WIndows 2000-Desktop icons not Displaying In My System After Booting process display one message "Userenv.dll is missing" after click on that not displaying the desktop...
1
by: SenthilPSL | last post by:
When I call a webservice on IIS on Windows 2000 Server with .NET runtime 2.0, I get the following Error. System.Net.WebException: The operation has timed out From ASPX Pages, I call the web...
2
by: Jack | last post by:
Sorry for the double post (also in the IIS group). We've got an ASP.Net 2.0 app running on IIS6. We kept losing sessions, and enabled health monitoring to see what was happening. This morning...
5
by: sklett | last post by:
I know that Panel (and most of it's derivitives) don't raise keyboard events. I *really* need to catch keyboard events though so I've been googling the topic and have found quite a few...
6
by: chrisli | last post by:
Hi everyone, i'm trying to Handle the Micosoft.Win32.SessionSwitch Event, so when Windows is going to be locked by the user, i will simply write a line to the console.When it's going to be...
4
by: lily86 | last post by:
i'm using visual studio 2003 - vb to write one printing system.... then i set my system to auto startup now i want lock the desktop when my system is running untill user key in the correct password...
1
by: Shyguy30 | last post by:
Hi. I am trying to render a sql report server report as a pdf an get the following Event code: 3005 Event message: An unhandled exception has occurred. Event time: 9/13/2010 10:47:10 AM ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.