我知道如果你运行:
rundll32.exe desk.cpl,InstallScreenSaver toasters.scr
您可以将屏幕保护程序设置为,toasters.scr
但它也会打开屏幕保护程序配置对话框。有没有办法在 Windows 上设置屏幕保护程序而无需通过运行命令打开任何对话框?
我知道如果你运行:
rundll32.exe desk.cpl,InstallScreenSaver toasters.scr
您可以将屏幕保护程序设置为,toasters.scr
但它也会打开屏幕保护程序配置对话框。有没有办法在 Windows 上设置屏幕保护程序而无需通过运行命令打开任何对话框?
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name ScreenSaveActive -Value 1
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name ScreenSaveTimeOut -Value 60
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name scrnsave.exe -Value "c:\windows\system32\mystify.scr"
您可以将它们放在ScrnInstaller.ps1
使用以下命令执行的脚本中:
$ powershell -WindowStyle hidden -f "ScrnInstaller.ps1"
注意:这些参数被组策略参数取代(例如,为企业中的用户强制设置屏幕保护程序)。你有几种方法可以在这里强制它。
使用 powershell 和组策略,您可以管理您正在影响更改的组织单位/域/站点 ,并且它优先于用户设置。
在屏幕保护程序超时的情况下更改组策略:
Get-Command -Module GroupPolicy
New-GPO -Name "ScreenSaverTimeOut" -Comment "Sets the time to 900 seconds"
Set-GPRegistryValue -Name "ScreenSaverTimeOut" -Key "HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop" -ValueName ScreenSaveTimeOut -Type DWord -Value 900
New-GPLink -Name "ScreenSaverTimeOut" -Target "ou=MyOU,dc=myenterprise,dc=com"
gpupdate /force /target:computer
对于 myenterprise.com。对于 New-GPLink 参数:msdn 参考
然后您可以查看您的全科医生:
Get-GPO -Name "ScreenSaverTimeOut" | Get-GPOReport -ReportType HTML -Path $Home\report.html
Invoke-Item $Home\report.html
我找到了两种方法:
1)添加注册表,确保处于活动状态并设置超时(仅几分钟)
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
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,则不能这样做。
而不是运行该命令,您应该只运行该命令
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d C:\Windows\system32\toasters.scr /f
这将更新屏幕保护程序
c:\Windows\System32\scrnsave.scr -start
上面的活在一个批处理文件中会启动空白屏幕保护程序。优点;用 C:\Windows\system32\ 中的其他 5 个屏幕保护程序之一替换 scrnsave.scr 也可以。您无需重新启动系统,它会立即启动。缺点;我不知道如何设置超时。我怀疑该行会有一个参数,就像c:\Windows\System32\scrnsave.scr /ScreenSaveTimeOut = 150 -start
我认为需要一个单独的批处理文件来停止屏幕保护程序一样。