Detecting Screen saver running, desktop lock and unlock event

cskiong
cskiong used Ask the Experts™
on
Hi Experts,

Is there a way to detect the following event on windows?
1. Screen saver starts running (due to idle).
2. Computer lock (User locks computer by Ctrl+Alt+Del or [Windows] key + L)
3. Resume from screen saver or computer lock.

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
ad 1)
You can use SystemParametersInfo with the SPI_GETSCREENSAVERRUNNING flag
anyoneisSoftware Developer
Top Expert 2006

Commented:
This should get you going: http://dotnet.sys-con.com/node/105651
David
Commented:
1) I'm using Timer event to pool the SPI_GETSCREENSAVERRUNNING flag.  This works fine, but I'm still looking for event triggering type of solution instead of constantly checking the flag.

2) I'm using WTS_SESSION_LOCK and WTS_SESSION_UNLOCK to detect Computer lock and unlock event.

3) Combining the solution 1 and 2.

I'm looking forwards better implementation in detecting the Screen Server start and resume event.
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Commented:
I do not know the situation in your system but you can always write your own screen saver and send kind of message from it. But this will work only in your own environment.

Commented:
I've got better screensaver start detection: trap messages and when screensaver is started there is WM_SYSCOMMAND with SC_SCREENSAVE sent by the system.
Commented:
And one thing more. But it seems to be the best:
look at http://msdn.microsoft.com/en-us/library/aa380545(VS.85).aspx
and http://msdn.microsoft.com/en-us/library/aa380544(VS.85).aspx for messages

there are messages for:
- StartScreenSaver
- StopScreenSaver
- Lock
- Unlock

and some others you didn's asked for.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial