Created
April 25, 2020 10:23
-
-
Save maxkoshevoi/b8a1ad91f4d2a9fd3931168c14080694 to your computer and use it in GitHub Desktop.
Change screen brightness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Management; | |
public static class MonitorBrightness | |
{ | |
public static int Get() | |
{ | |
using var mclass = new ManagementClass("WmiMonitorBrightness") | |
{ | |
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 Set(int brightness) | |
{ | |
using var mclass = new ManagementClass("WmiMonitorBrightnessMethods") | |
{ | |
Scope = new ManagementScope(@"\\.\root\wmi") | |
}; | |
using var instances = mclass.GetInstances(); | |
var args = new object[] { 1, brightness }; | |
foreach (ManagementObject instance in instances) | |
{ | |
instance.InvokeMethod("WmiSetBrightness", args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment