Skip to content

Instantly share code, notes, and snippets.

@aNNiMON
Created April 6, 2014 08:37
Show Gist options
  • Save aNNiMON/10003154 to your computer and use it in GitHub Desktop.
Save aNNiMON/10003154 to your computer and use it in GitHub Desktop.
public static ushort GetMonitorBrightness() {
using (var mclass = new ManagementClass("WmiMonitorBrightness")) {
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
using (var instances = mclass.GetInstances()) {
foreach (ManagementObject instance in instances) {
return (byte) instance.GetPropertyValue("CurrentBrightness");
}
}
}
return 0;
}
public static void SetMonitorBrightness(ushort brightness) {
using (var mclass = new ManagementClass("WmiMonitorBrightnessMethods")) {
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
using (var instances = mclass.GetInstances()) {
foreach (ManagementObject instance in instances) {
object[] args = new object[] { 1, brightness };
instance.InvokeMethod("WmiSetBrightness", args);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment