Beispiel #1
0
        /// <summary>
        /// Gets the value for the specified power plan, power mode and setting
        /// </summary>
        /// <param name="plan">Guid of the power plan</param>
        /// <param name="subgroup">The subgroup to look in</param>
        /// <param name="setting">The settign to look up</param>
        /// <param name="powerMode">Power mode. AC or DC, but not both.</param>
        /// <returns>The active index value for the specified setting</returns>
        public static uint GetPlanSetting(Guid plan, Guid subgroup, Guid setting, PowerMode powerMode)
        {
            if (powerMode == (PowerMode.AC | PowerMode.DC))
            {
                throw new ArgumentException("Can't get both AC and DC values at the same time, because they may be different.");
            }

            uint value = 0;
            uint res   = 0;

            if (powerMode.HasFlag(PowerMode.AC))
            {
                res = PowerReadACValueIndex(IntPtr.Zero, ref plan, ref subgroup, ref setting, out value);
            }
            else if (powerMode.HasFlag(PowerMode.DC))
            {
                res = PowerReadDCValueIndex(IntPtr.Zero, ref plan, ref subgroup, ref setting, out value);
            }

            if (res != (uint)ErrorCode.SUCCESS)
            {
                throw new Win32Exception((int)res);
            }

            return(value);
        }
Beispiel #2
0
 /// <summary>
 /// Alters a setting on a power plan.
 /// </summary>
 /// <param name="plan">The Guid for the plan you are changing</param>
 /// <param name="subgroup">The Guid for the subgroup the setting belongs to</param>
 /// <param name="setting">The Guid for the setting you are changing</param>
 /// <param name="powerMode">You can chose to alter the AC value, the DC value or both using the bitwise OR operator (|) to join the flags.</param>
 /// <param name="value">The new value for the setting. Run <code>powercfg -q</code> from the command line to list possible values</param>
 public static void SetPlanSetting(Guid plan, Guid subgroup, Guid setting, PowerMode powerMode, uint value)
 {
     if (powerMode.HasFlag(PowerMode.AC))
     {
         var res = PowerWriteACValueIndex(IntPtr.Zero, ref plan, ref subgroup, ref setting, value);
         if (res != (uint)ErrorCode.SUCCESS)
         {
             throw new Win32Exception((int)res);
         }
     }
     if (powerMode.HasFlag(PowerMode.DC))
     {
         var res = PowerWriteDCValueIndex(IntPtr.Zero, ref plan, ref subgroup, ref setting, value);
         if (res != (uint)ErrorCode.SUCCESS)
         {
             throw new Win32Exception((int)res);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Alters a setting on a power plan.
        /// </summary>
        /// <param name="plan">The Guid for the plan you are changing</param>
        /// <param name="subgroup">The Guid for the subgroup the setting belongs to</param>
        /// <param name="setting">The Guid for the setting you are changing</param>
        /// <param name="powerMode">You can chose to alter the AC value, the DC value or both using the bitwise OR operator (|) to join the flags.</param>
        /// <param name="value">The new value for the setting. Run <code>powercfg -q</code> from the command line to list possible values</param>
        public static void SetPlanSetting(Guid plan, SettingSubgroup subgroup, Setting setting, PowerMode powerMode, uint value)
        {
            Guid subgroupId = SettingIdLookup.SettingSubgroupGuids[subgroup];
            Guid settingId  = SettingIdLookup.SettingGuids[setting];

            if (powerMode.HasFlag(PowerMode.AC))
            {
                var res = PowerWriteACValueIndex(IntPtr.Zero, ref plan, ref subgroupId, ref settingId, value);
                if (res != (uint)ErrorCode.SUCCESS)
                {
                    throw new Win32Exception((int)res);
                }
            }
            if (powerMode.HasFlag(PowerMode.DC))
            {
                var res = PowerWriteDCValueIndex(IntPtr.Zero, ref plan, ref subgroupId, ref settingId, value);
                if (res != (uint)ErrorCode.SUCCESS)
                {
                    throw new Win32Exception((int)res);
                }
            }
        }