CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Posts
    1

    How do I get / set power settings using C#?

    Am trying desperately to figure out how I can go through and change Windows power using my C# program. In particular, I need to be able to get the brightness level and auto dimmer level from the current power scheme.

    I found some resources on pinvoke.net (http://www.pinvoke.net/default.aspx/...tPowerPolicies) , but for some reason almost 100% of the code there produces errors when I try using it in my project.

    For example, I tried this code only to get an error from Visual Studio about how GLOBAL POWER POLICY AND POWER POLICY are missing an assembly reference.

    [DllImport("powrprof.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetCurrentPowerPolicies(out GLOBAL_POWER_POLICY pGlobalPowerPolicy,
    out POWER_POLICY pPowerPolicy);

    Any idea how I can do what I need to do?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Talking Re: How do I get / set power settings using C#?

    Quote Originally Posted by geekinchief.com View Post
    Am trying desperately to figure out how I can go through and change Windows power using my C# program. In particular, I need to be able to get the brightness level and auto dimmer level from the current power scheme.
    You can get the Brightness level of the monitor by using the GetDeviceGammaRamp API. Here is a nice thread on how to get the and set monitor brightness :

    http://www.codeguru.com/forum/showth...71#post1950071

    It is in VB.NET though, but you could easily try to convert it to C#.

    The power settings, hmm, i think you might be able to get them with the use of the [b]GetCurrentPowerPolicies API. You could also perhaps try WMI as well.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How do I get / set power settings using C#?

    You can perhaps also use PowerGetActiveScheme, PowerEnumerate APIs, but i think Vista doesn't like them...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured