Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 16-Nov-12 0:14am
v2

scoket,

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!

Hogan
 
Share this answer
 
Comments
scoket 19-Nov-12 1:08am    
thank you for your advice.
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).

C#
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
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900