What API call would I use to change brightness of laptop (.NET)?
Asked Answered
S

4

10

I have Windows Server 2008 installed on a Sony laptop and the brightness control doesn't work. I'd like to write a program to allow me to change it.

Currently what I have to do is open the Power control panel, click advanced settings, and fight through so many UAC boxes that anybody watching me must think I'm completely crazy.

I just want a simple little program to do it but I don't know what API to call.

Sacttler answered 17/12, 2008 at 0:34 Comment(1)
See my answer here. It has code.Thumb
D
9

I looked up John Rudy's link to WmiSetBrightness in MSDN and came up with this:

ManagementClass mclass = new ManagementClass("WmiMonitorBrightnessMethods");
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
ManagementObjectCollection instances = mclass.GetInstances();

// I assume you get one instance per monitor
foreach(ManagementObject instance in instances)
{
    ulong timeout = 1; // in seconds
    ushort brightness = 50; // in percent
    object[] args = new object[] { timeout, brightness };
    instance.InvokeMethod("WmiSetBrightness", args);
}

Note: ManagementClass, ManagementObjectCollection, and ManagementObject all implement IDisposable. You should call Dispose() or use "using" to avoid leaking resources.

Disparagement answered 28/4, 2009 at 18:15 Comment(0)
P
2

This is vista only:

http://msdn.microsoft.com/en-us/library/ms775232.aspx

You need to identify the monitor with GetPhysicalMonitorsFromHMONITOR before setting its brightness with SetMonitorBrightness. I suspect nobody's done it before in .net so you'll probably need to write your own interop. The api doesn't appear to be particularly difficult so you should be able to do it pretty easily.

Paleography answered 17/12, 2008 at 0:42 Comment(0)
E
1

As far as I'm aware, there are no managed (.NET) APIs for this. However, for Vista, there are unmanaged APIs available via interop. See MSDN: Monitor Configuration APIs and WmiSetBrightness.

There may be managed ways of hitting the WmiSetBrightness method, but I'm not aware of them.

If you're not on Vista or Server 2008, you're in for a world of unpleasantness: The software configuration would have to be done directly through the monitor driver. Based on your mentioning UAC above, I suspect this isn't the case for you, but the next guy might want to know. :)

Electrolyse answered 17/12, 2008 at 0:43 Comment(0)
D
1

Just a brainstormer here... On the laptop you can change the brightness using some key-kombinations on the keyboard. It should be possible to send those keyspresses If you just want to make it darker/lighter and not have to set it to a specific value.

Dialyze answered 17/12, 2008 at 0:53 Comment(2)
the problem is that stupid sony has a driver for brightness (its not hardware based). i just couldnt get it working with 2008 server with UAC. never tried withoutSacttler
cos you know you REALLY need an onscreen indication that brightness has changed. and a beep. i got the volume control working, but brightness doesntSacttler

© 2022 - 2024 — McMap. All rights reserved.