以编程方式更改 Windows 电源设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3802301/
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
Programmatically change Windows power settings
提问by Petrus Theron
Is it possible to change the power-saving behaviour of a laptop computer on lid close from hibernate/standby/shutdownto Do Nothingfrom the .NET Framework?
是否可以将笔记本电脑在关闭盖子时的节能行为从休眠/待机/关机更改为从 .NET Framework不执行任何操作?
Edit:it would appear that by setting the value to Standby and blocking the standby from my application, the lid close event can be detected, which is what I'm really after.
编辑:似乎通过将值设置为 Standby 并阻止我的应用程序中的待机,可以检测到盖子关闭事件,这就是我真正想要的。
I found this questionwhich deals with detecting lid close, but it boils down to using a standby event or writing a driver.
我发现这个问题涉及检测盖子关闭,但归结为使用待机事件或编写驱动程序。
采纳答案by nrocha
Yes, you can use the WMI classes.
是的,您可以使用 WMI 类。
Take a look hereto an introduction to WMI
看这里对 WMI 的介绍
Note that you can also use Application.SetSuspendState
, but this method only allows you to suspend or hibernate. So I guess it doesn't match your needs...
请注意,您也可以使用Application.SetSuspendState
,但此方法仅允许您暂停或休眠。所以我想它不符合您的需求......
About the lid, there seems to be a wayto detect if the lid is closed or not...
关于盖子,似乎有一种方法可以检测盖子是否关闭......