Skip to content

Instantly share code, notes, and snippets.

@maxkoshevoi
Created April 25, 2020 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxkoshevoi/b8a1ad91f4d2a9fd3931168c14080694 to your computer and use it in GitHub Desktop.
Save maxkoshevoi/b8a1ad91f4d2a9fd3931168c14080694 to your computer and use it in GitHub Desktop.
Change screen brightness
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