Advertisement
Guest User

Ciaran

a guest
Dec 14th, 2010
1,893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Management;
  6.  
  7. namespace Brightener
  8. {
  9.     class Program
  10.     {
  11.  
  12.         public static void Main(string[] args)
  13.         {
  14.             try
  15.             {
  16.                 setBrightness(int.Parse(args[0]));
  17.             }
  18.             catch (Exception ex)
  19.             {
  20.                 Console.WriteLine("Please enter a number between 1 and 100");
  21.             }
  22.  
  23.         }
  24.  
  25.         private static void setBrightness(int brightnessLevel)
  26.         {
  27.             try
  28.             {
  29.                 ManagementScope s = new ManagementScope("root\\WMI");
  30.  
  31.                 SelectQuery q = new SelectQuery("WmiMonitorBrightnessMethods");
  32.  
  33.                 ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(s, q);
  34.  
  35.                 ManagementObjectCollection moc = mos.Get();
  36.  
  37.                 foreach (System.Management.ManagementObject o in moc)
  38.                 {
  39.                     o.InvokeMethod("WmiSetBrightness", new object[] {
  40.                     UInt32.MaxValue,
  41.                     brightnessLevel
  42.                 });
  43.  
  44.                 }
  45.  
  46.                 moc.Dispose();
  47.                 mos.Dispose();
  48.             }
  49.             catch (Exception ex)
  50.             {
  51.                 Console.WriteLine(ex.ToString());
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement