windows 如何以编程方式将“唤醒时需要密码”的值更改为 false?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6409711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:06:59  来源:igfitidea点击:

How can I change the value on "require a password on wakeup" to false programmatically?

c#.netwindows

提问by sari k

How can I change the value on "require a password on wakeup" to false in power options programmatically using C#. Currently it requires a password to unlock the computer when it wakes from sleep

如何使用 C# 以编程方式在电源选项中将“唤醒时需要密码”的值更改为 false。目前它需要密码才能在计算机从睡眠中唤醒时解锁

by manual: power options-> advanced settings-> balanced-> require a password on wakeup -> on battery:yes plugged in:yes

手动:电源选项-> 高级设置-> 平衡-> 唤醒时需要密码-> 电池:是 已插入:是

回答by Heinzi

The easiest way is by modifying the registry:

最简单的方法是修改注册表

In the HKEY_CURRENT_USER\Control Panel\Desktopregistry key, change the value of ScreenSaverIsSecureto 0.

HKEY_CURRENT_USER\Control Panel\Desktop注册表项中,将 的值更改ScreenSaverIsSecure0

(According to KB 928717, that's the correct registry key for modifying the "Require a password on wakeup" option.)

(根据KB 928717,这是修改“唤醒时需要密码”选项的正确注册表项。)

回答by CodesInChaos

Generally you should use SystemParametersInfowhere available instead of changing the registry yourself.

通常,您应该在可用的情况下使用 SystemParametersInfo而不是自己更改注册表。

Perhaps SystemParametersInfowith the SPI_SETSCREENSAVESECUREparameter does what you want. It exists only on Vista or later. I haven't tried it myself, but from the description it might be what you want.

也许带有参数的SystemParametersInfo 可以满足SPI_SETSCREENSAVESECURE您的需求。它仅存在于 Vista 或更高版本上。我自己没有尝试过,但从描述来看,它可能是您想要的。