Example #1
0
        public void SwitchPowerPlan(PowerPlan plan)
        {
            Guid powerPlanGuid = plan.Guid;

            if (powerPlanGuid != Guid.Empty)
            {
                uint retCode = PowerSetActiveScheme(IntPtr.Zero, ref powerPlanGuid);
                if (retCode != (uint)SystemCodes.ERROR_SUCCESS)
                {
                    throw GetLastError("PowerSetActiveScheme call failed", retCode);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Get this computer available power plans.
        /// </summary>
        /// <returns><see cref="List{string}"/> of power plans names.</returns>
        public List <PowerPlan> EnumeratePowerPlans()
        {
            List <PowerPlan> guidsNames = new List <PowerPlan>();
            List <Guid>      guids      = ListPowerPlans();
            PowerPlan        current    = GetActivePowerPlan();

            for (int i = 0; i < guids.Count; i++)
            {
                Guid guid = guids[i];
                guidsNames.Add(new PowerPlan(guid, ReadFriendlyName(ref guid), guid == current.Guid));
            }

            return(guidsNames);
        }