public static PowerState GetPowerState() { PowerState state = new PowerState(); if (GetSystemPowerStatusRef(state)) return state; throw new ApplicationException("Unable to get power state"); }
private static extern bool GetSystemPowerStatusRef(PowerState sps);