views:

897

answers:

1

I'm working on code that's supposed to start the screensaver defined by the user preferences. (The code is in Java, but will only be run under Windows.) My current approach is to set the ScreenSaveTimeOut value in the registry to 1; in theory, that should kick the screensaver on after a delay of merely one second.

But in practice, it does no such thing. I've hit the values in both HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveTimeOut and HKEY_USERS.DEFAULT\Control Panel\Desktop\ScreenSaveTimeOut with no results. I can see the values change when I fire up regedit, but the "Wait" value in Display Properties -> Screen Saver doesn't change.

An Experts-Exchange thread indicated I ought to do this to make the changes effective immediately:

%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

... but that didn't seem to do anything.

Any advice or insights into what I'm doing wrong?

+2  A: 

To activate the screen saver, you might find it easier just to execute the .SCR file with a '/s' parameter, like so:

C:\WINDOWS\system32\ssstars.scr /s

Or, I can't say much about how to do this from Java, but if you can call the functions in user32.dll you can control the screen saver like an end-user. Here are a couple links:

(Lastly, there's the .NET method, but again I have no idea how to get that from Java: http://zayko.net/post/C-How-To-Disable-Windows-Screensaver-programmatically.aspx)

ewall
I was going to suggest this same thing. Any reason why you need to change the registry settings, Blair?
JasCav
+1 for guessing my Plan B. :-) Jason, I don't NEED to, I'm just gunning for the most elegant solution. If I go with this approach, I'll also have to code-in some simulated mouse movement to prevent the screensaver from coming on when I don't want it. Which is quite doable, just a bit hack-y for my liking. Playing around with ScreenSaveTimeOut (and possibly ScreenSaveActive -- don't know that I'll need to, since I think setting ScreenSaveTimeOut=0 disables the screen saver) struck me as having fewer moving parts.
BlairHippo
Never did really figure this one out, so I went with Plan B. May as well hand-out a checkmark for it. :-)
BlairHippo

related questions