Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Win7
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
scoket428
Edited 16-Nov-12 1:14am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
scoket at 19-Nov-12 1:08am
   
thank you for your advice.
Rate this: bad
good
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).
 
 
    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
  Permalink  
Comments
msiterten at 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
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
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