10

As the title asks (Windows 7). (How) can I change the time until the screensaver kicks in from the command line? Is it even possible?

Normally I am happy with a 5 minute setting, but occasionally I want to make it longer. I would like the two lengths bound to hot-keys (I know how to do that).

I guess I could record two macros and use those, but I just wondered if there are any command line options (including registry updates) that I can use to tell Windows to start the screen saver after X minutes of inactivity.

(please note, I do not want to start the screen saver immediately; I want to change the length of time Windows will wait before starting it)

Thanks in advance.


[Answer] I finally used a variation on the answer from @Gjordis - but all credit goes to him.

I didn't see why we needed 3 operations : add, delete then rename and reduced that to two.

Since I want to bind to a hotkey, I need to execute two comamnds in one. Normally, one can separate the commands with a semicolon and issue them on one line (e.g dir c:;dir d:). That gave errors with the reg command, so in the end I have two batch files. The contens are identitcal, only the duration changes.

On strange thing - the value is correctly written to the registry, but Control Panel/Personalize/Screen saver does not alwys update its GUI. However, I tested and the screen saver does behave as expected.

@echo off
reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /f
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 180 /f

If this helps you, please upvote the question ;-)

4 Answers 4

7
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 600 /f

The value 600 is in seconds, = 10minutes Interestingly, as pointed, this works only the first time. On next change, you need to make a new key like so :

reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOutTemp /t REG_SZ /d 300 /f

Then delete the old one

reg delete "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 600 /f

Then copy the new one to the right name

reg copy "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOutTemp "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut

Hopy this works, and you do not destory your computer, but since you did not have this registry value, i don't think deleting it can be that horrible.

REG documentation here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/reg.mspx?mfr=true

5
  • That works :-) The first time only :-( presumably because I didn't have a registry entry the frist time, so could add, but might need to modify subsequently? +1 for trying. Thanks
    – Mawg
    Mar 5, 2013 at 8:04
  • 1
    Edited to hopefully work other times too
    – Gjordis
    Mar 5, 2013 at 8:14
  • +1 Well, that's trange. I can see that it is updating the registry key, but when I right click the desktop (or go via control panel) and choose "peronalize", it still shows 5 mintes on the GUI. If I set 10 seconds via registry, the screen saver does not start after 10 seconds (or even a few minutes). If I set 1 minute in the GUI then it does start after 1 minute (and it updates the registry correctly).
    – Mawg
    Mar 5, 2013 at 8:44
  • Perhaps it has a valid value -range
    – Gjordis
    Mar 5, 2013 at 8:46
  • +1 I used a variation on your answer and have posted it in the qustion above. Thanks for your help
    – Mawg
    Mar 6, 2013 at 2:35
2

In fact, this approach (via registry) doesn't work until reboot. Only way to do that without PC reboot is to use an API:

https://www.pcreview.co.uk/threads/utility-to-temporarily-change-the-screensaver.2321339/#post-7442568

but APIs can't be used from a command line, i.e. VB script. Here is the reason:

http://forums.codeguru.com/showthread.php?31534-VBScript-and-API&p=86696#post86696

It could be done by calling utility SetScrTimeout.exe (from the first link), but unfortunatelly, this small utility doesn't exist on internet anymore.

5
  • Thanks for that. Perhaps SetScrTimeout.exe can be founds on the way back machine? I can't check because of the company firewall, but it should be there - everything else is ;-)
    – Mawg
    Nov 21, 2018 at 12:42
  • 1
    I even tried on ftp servers, but no result. I have found an VB source code for that purpose (freevbcode.com/ShowCode.asp?ID=504), but I am not able to make and share an exe.
    – Aleksandar
    Nov 22, 2018 at 12:00
  • Any idea which version of VB (I am guessing VN 6)?
    – Mawg
    Nov 22, 2018 at 12:44
  • 1
    Yes, it is VB6. Sorry for my late reply.
    – Aleksandar
    Nov 4, 2019 at 8:43
  • I can share this program, which is similar SetScrTimeout.exe: link Usage ===== To set the screensaver timeout value to 60 seconds, use this command: ScrSav.exe -t60
    – Aleksandar
    Feb 24, 2023 at 10:20
1

For an alternative to the "single use" utilities described before, AutoHotkey allows to call the Win32 API (and the SystemParametersInfoA function) directly.

The following line does the job:

DllCall("SystemParametersInfo", "Uint", 15, "Uint", 360)

The SystemParametersInfoA function can take multiple parameters, in this case we only need two, uiAction and uiParam.

  • uiAction: the code for the action (15 for SPI_SETSCREENSAVETIMEOUT).

  • uiParam: the timeout in seconds (360 in this example).

I tested it in Windows 11 but should work in previous versions as well.

1

This works great for me. I doubt it's malware, but I can't guarantee. In windows 11, I download it and create any taskbar icon to pin, right click, goto properties and change the path and icon of the short cut to match SetScrTimeout.exe where I downloaded it.

I've got one (tskbar icon) set to 1 second, and another set to 2400 seconds, which is 40 minuets. I made a hot key in the properties of the shortcuts on the task bar. ctrl+shift+z does one icon and ctrl+shift+x does the other.

If you set your screen timeout to 1 second, it actually take a couple seconds to run, so if you move your mouse, it reinitiates after 2 or 3 seconds. As long as your mouse is moving it won't activate.

Great for when I'm falling asleep after pausing youtube...

example:

c:\users\johndoe\docs\SetScrTimeout.exe 10

https://github.com/DavisNT/SetScrTimeout

https://github.com/DavisNT/SetScrTimeout/releases/download/v1.0.0/SetScrTimeout.exe

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .