设置Windows屏幕保护程序需要使用PowerShell密码

我知道我可以通过registry设置屏幕保护程序的值,但这些都适用于login。 我收集正确的方法是使用SystemParametersInfo函数,然后立即应用更改。

我能够得到并设置屏幕保护程序超时值使用以下内容:

$signature = @" [DllImport("user32.dll")] public static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags ); "@ $systemParamInfo = Add-Type -memberDefinition $signature -Name ScreenSaver -passThru Function Get-ScreenSaverTimeout { [Int32]$value = 0 $systemParamInfo::SystemParametersInfo(14, 0, [REF]$value, 0) $($value/60) } Function Set-ScreenSaverTimeout { Param ([Int32]$value) $seconds = $value * 60 [Int32]$nullVar = 0 $systemParamInfo::SystemParametersInfo(15, $seconds, [REF]$nullVar, 2) } 

来自https://powershellreflections.wordpress.com/2011/08/02/control-your-screensaver-with-powershell/

我正在尝试更改“恢复,显示login屏幕”的标志。 获得以下价值是成功的:

 function Get-ScreenSaverSecure { [Int32]$value = 0 $systemParamInfo::SystemParametersInfo(118, 0, [REF]$value, 0) $value } 

但是,将值设置为:

 Function Set-ScreenSaverSecure { [Int32]$nullVar = 0 $systemParamInfo::SystemParametersInfo(119, $true, [REF]$nullVar, 2) } 

不设置标志。 从MSDN链接,我认为我应该传递SPI_SETSCREENSAVESECURE(这是uiParam 119)$ true或$ false,取决于模式,但似乎都不适用。

任何帮助表示赞赏。