Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silently set the screensaver on Windows from the command line?

I know that if you run:

rundll32.exe desk.cpl,InstallScreenSaver toasters.scr

you can set the screensaver to toasters.scr but it also opens up the screensaver configuration dialog. Is there a way to set the screensaver on Windows without opening any dialog by running a command?

like image 833
pupeno Avatar asked Apr 12 '18 08:04

pupeno


People also ask

How do I change my screensaver in CMD?

You can also open screen saver setting from command prompt in Windows 10, here's how: Bring up the Run box by pressing the Windows key + R. Type the command control desk. cpl,,@screensaver and hit Enter.

How do I manually trigger my screensaver?

Right-click on the desktop, choose Personalize, and then click on Screen Saver on the bottom right-hand side of the window.


1 Answers

I have found two ways to do it:

1) Add in registry, make sure is active and setTimeOut (only minutes)

CMD

reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d C:\Windows\System32\Mystify.scr /f
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 1 /f
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 60 /f

JAVA

setScreenSaver(true, 1, "C:\\Windows\\System32\\Mystify.scr");

/**
 * set screen saver active, timeout and scr, only works in Windows
 * @param isActive
 * @param timeOutMin only minutes
 * @param pathToScr path to scr
 * @throws IOException
 */
public static void setScreenSaver(boolean isActive, int timeOutMin, String pathToScr) throws IOException{
    String _isActive = isActive ? "1" : "0";
    //only works with minutes, min. 1 min
    String _timeOut = timeOutMin > 1 ? timeOutMin*60+"" : "60";
    Runtime.getRuntime().exec(new String[] { "reg", "add", "HKEY_CURRENT_USER\\Control Panel\\Desktop", "/v", "SCRNSAVE.EXE", "/t", "REG_SZ", "/d", pathToScr,"/f" });
    Runtime.getRuntime().exec(new String[] { "reg", "add", "HKEY_CURRENT_USER\\Control Panel\\Desktop", "/v", "ScreenSaveActive", "/t", "REG_SZ", "/d", _isActive,"/f" });
    Runtime.getRuntime().exec(new String[] { "reg", "add", "HKEY_CURRENT_USER\\Control Panel\\Desktop", "/v", "ScreenSaveTimeOut", "/t", "REG_SZ", "/d", _timeOut,"/f" });
}

2) Get path from registry and rewrite scr file, but if is set to null, you can't do it.

like image 140
Maciej Pulikowski Avatar answered Oct 02 '22 14:10

Maciej Pulikowski