-
August 2nd, 2010, 09:52 AM
#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?
-
August 3rd, 2010, 01:45 AM
#2
Re: How do I get / set power settings using C#?
Originally Posted by geekinchief.com
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.
-
August 3rd, 2010, 01:58 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|