windows C#:在电源计划之间切换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5991333/
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 16:50:51  来源:igfitidea点击:

C# : Switch between power plans

c#windowsregistry

提问by BOSS

i am creating an API and i want to switch between power plans

我正在创建一个 API,我想在电源计划之间切换

[Balanced , High performance , Power saver]

[平衡,高性能,省电]

, my problem isn`t on the code , coding is easy , but i want to know where can i find these power planes .exe files or even values in registry to modify it

,我的问题不在于代码,编码很容易,但我想知道在哪里可以找到这些电源平面 .exe 文件甚至注册表中的值来修改它

回答by RB.

Raymond Chen's latest post happens to be about this, and he suggests the following:

Raymond Chen的最新帖子恰好是关于这个的,他提出以下建议:

If you are using Vista or above, from the command line, run :

如果您使用的是 Vista 或更高版本,请从命令行运行:

powercfg -aliases

However, this doesn't work for me as -aliasesis not a valid switch on Windows XP.

但是,这对我不起作用,因为-aliases它不是 Windows XP 上的有效开关。

EDIT: Or, you can just use this list of helpful GUIDs!

编辑:或者,您可以使用这个有用的 GUID 列表

回答by Till

While you could certainly use an external tool like powercfg, you could just as well use the Power Management API

虽然您当然可以使用像 powercfg 这样的外部工具,但您也可以使用电源管理 API

http://msdn.microsoft.com/en-us/library/aa372711%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/aa372711%28v=VS.85%29.aspx

Or Windows Management Instrumenation (WMI)

或 Windows 管理规范 (WMI)

http://msdn.microsoft.com/en-us/library/dd904518%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/dd904518%28v=VS.85%29.aspx

回答by Hans Passant

You'll find them in the winnt.h SDK header file. Stored in c:\program files\microsoft sdks\windows\v6.0a\include for VS2008, v7.0a for VS2010. Search for "GUID_MAX_POWER_SAVINGS" to find this:

您将在 winnt.h SDK 头文件中找到它们。存储在 c:\program files\microsoft sdks\windows\v6.0a\include for VS2008, v7.0a for VS2010。搜索“GUID_MAX_POWER_SAVINGS”来找到这个:

// =========================================
// Define GUIDs which represent well-known power schemes
// =========================================
//

//
// Maximum Power Savings - indicates that very aggressive power savings measures will be used to help
//                         stretch battery life.
//
// {a1841308-3541-4fab-bc81-f71556f20b4a}
//
DEFINE_GUID( GUID_MAX_POWER_SAVINGS, 0xA1841308, 0x3541, 0x4FAB, 0xBC, 0x81, 0xF7, 0x15, 0x56, 0xF2, 0x0B, 0x4A );

//
// No Power Savings - indicates that almost no power savings measures will be used.
//
// {8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}
//
DEFINE_GUID( GUID_MIN_POWER_SAVINGS, 0x8C5E7FDA, 0xE8BF, 0x4A96, 0x9A, 0x85, 0xA6, 0xE2, 0x3A, 0x8C, 0x63, 0x5C );

//
// Typical Power Savings - indicates that fairly aggressive power savings measures will be used.
//
// {381b4222-f694-41f0-9685-ff5bb260df2e}
//
DEFINE_GUID( GUID_TYPICAL_POWER_SAVINGS, 0x381B4222, 0xF694, 0x41F0, 0x96, 0x85, 0xFF, 0x5B, 0xB2, 0x60, 0xDF, 0x2E );

回答by Andy

Here is an example of Power Management API usage: PowerManager.cs

以下是电源管理 API 使用示例:PowerManager.cs

回答by Stecya

You can use Powercfgcommand from command-line

您可以从命令行使用Powercfg命令