change brightness c# code example

Example: change brightness c#

/// A class to control Windows screen brightness:
public static class WindowsSettingsBrightnessController
    {
        public static int Get()
        {
            var mclass = new ManagementClass("WmiMonitorBrightness");
            ManagementScope Scope = new ManagementScope(@"\\.\root\wmi");
            var instances = mclass.GetInstances();
            foreach (ManagementObject instance in instances)
            {
                return (byte)instance.GetPropertyValue("CurrentBrightness");
            }
            return 0;
        }

        public static void Set(int brightness)
        {
            var mclass = new ManagementClass("WmiMonitorBrightnessMethods");
            ManagementScope Scope = new ManagementScope(@"\\.\root\wmi");
            var instances = mclass.GetInstances();
            var args = new object[] { 1, brightness };
            foreach (ManagementObject instance in instances)
            instance.InvokeMethod("WmiSetBrightness", args);
        }
    }
/// And to use it:
public void Main(int val) {
	WindowsSettingsBrightnessController.Set(val);
}

Tags:

Misc Example