4

One solution that one could suggest is to periodically look for a special 'Screen-saver' desktop, and if it's present then count it as a running screensaver.

But apparently this is not the case for all screensavers as with some the mentioned desktop is always present.

Are there more reliable solutions for this?

mblsha
  • 447
  • 7
  • 9

5 Answers5

10

See the WINAPI function SystemParametersInfo() with the SPI_GETSCREENSAVERRUNNING parameter. It's the only documented way to detect whether the screen saver is currently running. (You can also find out if a screen saver is even enabled, get and set the timeout value, and start the screen saver using this function.)

Ken White
  • 123,280
  • 14
  • 225
  • 444
2

I think the key is to identify the screensaver by its window class ("WindowsScreenSaverClass"). I found this page How do I start, detect and stop screen savers? that has some code examples and explanations.

f3lix
  • 29,500
  • 10
  • 66
  • 86
1

HOW TO: Determine If Screen Saver Is Running by Using Visual Basic 6.0

I know this is for VB6, but it's bound to be a good place to start.

Galwegian
  • 41,475
  • 16
  • 112
  • 158
-1

This is my implementation of screen saver event detection.

Notes:

  • SPI_GETSCREENSAVERRUNNING detects Windows Event id 4802 and 4803 which weren't accurate in my case, see my problem hence user idle time calculation is added
  • GetLastInputInfo apparently doesn't work if process is a service.
Community
  • 1
  • 1
krizajb
  • 1,715
  • 3
  • 30
  • 43
-2

search processes for a process with .scr in its .MainModule.FileName

Mesh
  • 6,262
  • 5
  • 34
  • 53