Click here to Skip to main content
13,293,950 members (60,694 online)
Rate this:
Please Sign up or sign in to vote.
See more:
under Win7,open Control Panel -> Power Options -> Advanced Settings->Processor power management

you can see Minimum Processor state, Maximum Processor state.
I want to get the value of Processor state by C#.for example 5%,100%.
I use the command "powercfg" in c#,i noly can get the value of "monitor-timeout-ac" and so on.
I can not get the value of Processor state.
how to do it.
Any help will be appreciated.
Posted 16-Nov-12 1:02am
Updated 16-Nov-12 1:14am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Your best bet for this type of information is to explore the Windows WMI classes.

Basic Computer Hardware[^]
Power State Control[^]
CPU Values[^]

I probably didn't link you to the exact resource you need to complete your task, but I hope to give you and idea what's possible through WMI. I recommend a tool like WMI Explorer[^] to help you search through the possible classes to see what is available. There is a ton out there and you just have to play detective till you find what you're looking for, but it is there!

Good luck!

scoket 19-Nov-12 1:08am
thank you for your advice.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You need to dllimport powrprof.dll, and use ReadProcessorPwrScheme API, then access the processorPolicyInfoAc.DemotePercent and ProcessorPolicyInfoAc.PromotePercent

See the code bellow. Not tested but it will show you the way (I use this code to get DynamicThrottle information and it works).

            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;
            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;
            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()
            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
msiterten 3-Sep-13 8:38am
I cannot get solution 2 working. ReadProcessorPwrScheme always returns false. What am i doing wrong?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100