Trying to find the programming code that activates or deactivates the screensaver.

Hello, if you are reading this please can you tell me what programming code activates or deactivates the screensaver in Windows please?. I tried to find it but Microsoft is always hiding everything.

Last edited on
Not sure what you're trying to accomplish. I didn't find anything on interacting with the standard screen saver, but Microsoft does fully document how to write your own screen saver.
You can make it respond to Windows events however you wish.
Thank you for the information, this will help me. Have a good night.
I don't have a complete solution, but let's say you have the screensaver active through Desktop --> Personalize --> Lock screen --> Screen saver settings.

It can be programmatically enabled via the command-line with [1]
powershell.exe -command "& (Get-ItemProperty ‘HKCU:Control Panel\Desktop’).{SCRNSAVE.EXE}"

So there is some way of triggering the screensaver, which can be explored further.

I found [2], which is a C# interface for triggering the screensaver automatically. Yes, it's C#, but it's basically just calling into the Win32 SendMessage function, which you can write in C++.

Next, how can we programmatically disable the screensaver? As AbstractionAnon's article mentions, I suppose you can have another program send an event like WM_MOUSEMOVE. There might be other ways as well. Another article [3] appears to have code that can check to see if the screensaver is active, and disable the screensaver programmatically.


Last edited on
at one point, not sure if still true, the SS was just an exe renamed to .scr.
I remember setting a guy's outlook.exe to .scr and setting it so I could get into his mail after he logged out. It was... just a program, where the real SS agree to end on key or mouse event but that isn't even required.
they seem to start via windows just looking for it... somewhere in windows idle loop is a 'if idle time >= SS time and SS assigned, fire it up', and the program itself closes out on mouse/key (by agreement).

this was some versions of windows ago, though, probably win2000 or something era.
Topic archived. No new replies allowed.