在Win7下,打开Control Panel -> Power Options -> Advanced Settings->Processor power management
。
您可以看到最低处理器状态,最大处理器状态
我想通过C#得到处理器状态的值。例如5%,100%。
我在c#中使用命令“powercfg”,我不能得到“monitor-timeout-ac”的值等等。
我无法得到处理器的价值
状态。
我怎样才能做到这一点?
答案 0 :(得分:1)
您需要dllimport powrprof.dll,并使用ReadProcessorPwrScheme API,然后访问processorPolicyInfoAc.DemotePercent和ProcessorPolicyInfoAc.PromotePercent
请参阅下面的代码。没有经过测试但它会告诉你的方式(我使用这段代码来获取DynamicThrottle信息并且它可以工作)。
struct PROCESSOR_POWER_POLICY_INFO { public uint TimeCheck; public uint DemoteLimit; public uint PromoteLimit; public byte DemotePercent; public byte PromotePercent; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] Spare; public uint AllowBits; } struct PROCESSOR_POWER_POLICY { public uint Revision; public byte DynamicThrottle; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] Spare; public uint Reserved; public uint PolicyCount; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public PROCESSOR_POWER_POLICY_INFO[] Policy; } struct MACHINE_PROCESSOR_POWER_POLICY { public uint Revision; // ULONG public PROCESSOR_POWER_POLICY ProcessorPolicyAc; public PROCESSOR_POWER_POLICY ProcessorPolicyDc; } [DllImport("powrprof.dll", SetLastError = true)] static extern bool ReadProcessorPwrScheme(uint uiID, out MACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy); public void ReadProcessorPowerScheme() { MACHINE_PROCESSOR_POWER_POLICY machinep = new MACHINE_PROCESSOR_POWER_POLICY(); uint scheme = 0; if (ReadProcessorPwrScheme(scheme, out machinep)) { //Then loop through machinep.ProcessorPolicyAc.Policy[]; array //Use: PROCESSOR_POWER_POLICY_INFO processorPolicyInfoAc = mppp.ProcessorPolicyAc.Policy[i]; //Use: processorPolicyInfoAc.DemotePercent; //Use: processorPolicyInfoAc.PromotePercent; //And don't forget to do the same for Dc (Dc is battery) } }
Edgar Rocha Carvalho
答案 1 :(得分:0)
使用
PowerReadACValueIndex()/PowerReadDCValueIndex()
NULL
GUID
用于所需的电源方案(GUID_MAX_POWER_SAVINGS
/ GUID_MIN_POWER_SAVINGS
/ GUID_TYPICAL_POWER_SAVINGS
)GUID_PROCESSOR_SETTINGS_SUBGROUP
GUID_PROCESSOR_THROTTLE_MAXIMUM
或GUID_PROCESSOR_THROTTLE_MINIMUM
所有GUID
说明都可以在 winnt.h