472,331 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 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 21284

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...
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...
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...
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...
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...
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...
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...
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...
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...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.