从命令行静默设置Windows上的屏幕保护程序?(Silently set the screensaver on Windows from the command line?)

我知道如果你跑:

rundll32.exe desk.cpl,InstallScreenSaver toasters.scr

您可以将屏幕保护程序设置为toasters.scr但它也会打开屏幕保护程序配置对话框。 有没有办法在Windows上设置屏幕保护程序,而无需通过运行命令打开任何对话框?

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?

最满意答案

我找到了两种方法来做到这一点:

1)添加注册表,确保是活动的,setTimeOut(仅分钟)

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)从注册表中获取路径并重写scr文件,但如果设置为null,则不能这样做。

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.

更多推荐