我知道我可以通过注册表设置屏幕保护程序值,但这些值在登录时适用.我收集正确的方法是使用
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,[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/开始
我正在尝试更改“恢复时,显示登录屏幕”的标志.获得以下值是成功的:
function Get-ScreenSaverSecure { [Int32]$value = 0 $systemParamInfo::SystemParametersInfo(118,0) $value }
但是,设置值为:
Function Set-ScreenSaverSecure { [Int32]$nullVar = 0 $systemParamInfo::SystemParametersInfo(119,$true,2) }
没有设置标志.从MSDN链接,我认为我应该传递SPI_SETSCREENSAVESECURE(这是uiParam 119)$true或$false,具体取决于模式,但似乎都不适用.
任何帮助表示赞赏.
解决方法
我使用了@Tim AtLee的功能,并按如下方式定制:
Function Set-OnResumeDisplay@R_@R_301_449@_395@n { Param ([Int32]$value) [Int32]$nullVar = 0 $systemParamInfo::SystemParametersInfo(119,$value,2) }
然后叫:
Set-OnResumeDisplay@R_@R_301_449@_395@n(0)
Set-OnResumeDisplay@R_@R_301_449@_395@n(1)
将“On resume,display @R_@R_301_449@_395@n”标志设置为选中状态