473,388 Members | 1,574 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,388 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 21452

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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.