我想读取 BatteryLifePercent 的值,如果它高于 80%(0.80),则将 ACLineStatus 设置为离线。
我试过使用
[DllImport("kernel32.dll", SetLastError = true)]
private static extern Boolean GetSystemPowerStatus(out SystemPowerStatus sps);
private enum ACLineStatus : byte
{
Offline = 0,
Online = 1,
Unknown = 255
}
private enum BatteryFlag : byte
{
High = 1,
Low = 2,
Critical = 4,
Charging = 8,
NoSystemBattery = 128,
Unknown = 255
}
private struct SystemPowerStatus
{
public ACLineStatus LineStatus;
public BatteryFlag flgBattery;
public Byte BatteryLifePercent;
public Byte Reserved1;
public Int32 BatteryLifeTime;
public Int32 BatteryFullLifeTime;
}
public static Boolean ACPowerPluggedIn()
{
SystemPowerStatus SPS = new SystemPowerStatus();
GetSystemPowerStatus(out SPS);
if (SPS.LineStatus == ACLineStatus.Online)
{
return true;
}
else
{
return false;
}
}
public static Int32 BatteryCharge()
{
SystemPowerStatus SPS = new SystemPowerStatus();
GetSystemPowerStatus(out SPS);
return (Int32)SPS.BatteryLifePercent;
}
它可用于读取 BatteryLifePercent。但我不知道如何将 ACLineStatus 设置为离线以避免进一步充电。
我也想知道,是否可以使用 acpi 控制方法(http://msdn.microsoft.com/en-us/library/windows/hardware/ff536139(v=vs.85).aspx)?