命令行输出:
C:powercfg -availablesleepstates
The following sleep states are available on this system:
Standby (S3)
Hibernate
Hybrid Sleep
Fast Startup
The following sleep states are not available on this system:
Standby (S1)
The system firmware does not support this standby state.
Standby (S2)
The system firmware does not support this standby state.
Standby (S0 Low Power Idle)
The system firmware does not support this standby state.
powershell脚本:
$info = (powercfg /a | Select-String -Pattern "sleep states are available" -context 4) | select -Last 4
$items = $info -split ","
$ourObject = New-Object -TypeName psobject
$ourObject | Add-Member -MemberType NoteProperty -Name PCFG0bj -Value $items -Force
$ourObject | fl
Output:
PCFG0bj : {> The following sleep states are available on this system:
Standby (S3)
Hibernate
Hybrid Sleep
Fast Startup}
这是一个PowerShell函数,它直接公开SYSTEM_POWER_CAPABILITIES,正如@Persistent13所建议的那样。结构已更新为包含新变量,例如AoAc,以显示是否支持Modern Standby(S0(。SYSTEM_POWER_CAPABILITIES的更新定义比我想象的更难找到,因为Microsoft KB错误地显示了SYSTEM_BATTERY_STATE。我设法找到了一些可供选择的资源,这些资源链接在TypeDef中。
功能:
Function Get-PowerCapabilities
{
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
public static class PowerCfg
{
[DllImport("PowrProf.dll")]
public static extern bool GetPwrCapabilities(out SYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities);
public static SYSTEM_POWER_CAPABILITIES GetCapabilities()
{
SYSTEM_POWER_CAPABILITIES spc;
bool well = GetPwrCapabilities(out spc);
return spc;
}
// https://github.com/MicrosoftDocs/sdk-api/blob/docs/sdk-api-src/content/winnt/ns-winnt-system_power_capabilities.md
// https://www.pinvoke.net/default.aspx/Structures/SYSTEM_POWER_CAPABILITIES.html
[Serializable]
public struct SYSTEM_POWER_CAPABILITIES
{
[MarshalAs(UnmanagedType.I1)]
public bool PowerButtonPresent; //If this member is TRUE, there is a system power button.
[MarshalAs(UnmanagedType.I1)]
public bool SleepButtonPresent; //If this member is TRUE, there is a system sleep button.
[MarshalAs(UnmanagedType.I1)]
public bool LidPresent; //If this member is TRUE, there is a lid switch.
[MarshalAs(UnmanagedType.I1)]
public bool SystemS1; //If this member is TRUE, the operating system supports sleep state S1.
[MarshalAs(UnmanagedType.I1)]
public bool SystemS2; //If this member is TRUE, the operating system supports sleep state S2.
[MarshalAs(UnmanagedType.I1)]
public bool SystemS3; //If this member is TRUE, the operating system supports sleep state S3.
[MarshalAs(UnmanagedType.I1)]
public bool SystemS4; //If this member is TRUE, the operating system supports sleep state S4 (hibernation).
[MarshalAs(UnmanagedType.I1)]
public bool SystemS5; //If this member is TRUE, the operating system supports power off state S5 (soft off).
[MarshalAs(UnmanagedType.I1)]
public bool HiberFilePresent; //If this member is TRUE, the system hibernation file is present.
[MarshalAs(UnmanagedType.I1)]
public bool FullWake; //If this member is TRUE, the system supports wake capabilities.
[MarshalAs(UnmanagedType.I1)]
public bool VideoDimPresent; //If this member is TRUE, the system supports video display dimming capabilities.
[MarshalAs(UnmanagedType.I1)]
public bool ApmPresent; //If this member is TRUE, the system supports APM BIOS power management features.
[MarshalAs(UnmanagedType.I1)]
public bool UpsPresent; //If this member is TRUE, there is an uninterruptible power supply (UPS).
[MarshalAs(UnmanagedType.I1)]
public bool ThermalControl; //If this member is TRUE, the system supports thermal zones.
[MarshalAs(UnmanagedType.I1)]
public bool ProcessorThrottle; //If this member is TRUE, the system supports processor throttling.
public byte ProcessorMinThrottle; //The minimum level of system processor throttling supported, expressed as a percentage.
public byte ProcessorMaxThrottle; //The maximum level of system processor throttling supported, expressed as a percentage. Also known as ProcessorThrottleScale before Windows XP
[MarshalAs(UnmanagedType.I1)]
public bool FastSystemS4; //If this member is TRUE, the system supports the hybrid sleep state.
[MarshalAs(UnmanagedType.I1)]
public bool Hiberboot; //If this member is set to TRUE, the system is currently capable of performing a fast startup transition. This setting is based on whether the machine is capable of hibernate, whether the machine currently has hibernate enabled (hiberfile exists), and the local and group policy settings for using hibernate (including the Hibernate option in the Power control panel).
[MarshalAs(UnmanagedType.I1)]
public bool WakeAlarmPresent; //If this member is TRUE, the platform has support for ACPI wake alarm devices.
[MarshalAs(UnmanagedType.I1)]
public bool AoAc; //If this member is TRUE, the system supports the S0 low power idle model.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] spare2; //Unknown
[MarshalAs(UnmanagedType.I1)]
public bool DiskSpinDown; //If this member is TRUE, the system supports allowing the removal of power to fixed disk devices.
public byte HiberFileType; //Unknown
[MarshalAs(UnmanagedType.I1)]
public bool AoAcConnectivitySupported; //Unknown
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] spare3; //Reserved
[MarshalAs(UnmanagedType.I1)]
public bool SystemBatteriesPresent; //If this member is TRUE, there are one or more batteries in the system.
[MarshalAs(UnmanagedType.I1)]
public bool BatteriesAreShortTerm; //If this member is TRUE, the system batteries are short-term. Short-term batteries are used in uninterruptible power supplies (UPS).
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public BATTERY_REPORTING_SCALE[] BatteryScale; //A BATTERY_REPORTING_SCALE structure that contains information about how system battery metrics are reported.
public SYSTEM_POWER_STATE AcOnLineWake; //The lowest system sleep state (Sx) that will generate a wake event when the system is on AC power.
public SYSTEM_POWER_STATE SoftLidWake; //The lowest system sleep state (Sx) that will generate a wake event via the lid switch.
public SYSTEM_POWER_STATE RtcWake; //The lowest system sleep state (Sx) supported by hardware that will generate a wake event via the Real Time Clock (RTC).
public SYSTEM_POWER_STATE MinDeviceWakeState; //The minimum allowable system power state supporting wake events. Note that this state may change as different device drivers are installed on the system.
public SYSTEM_POWER_STATE DefaultLowLatencyWake; //The default system power state used if an application calls RequestWakeupLatency with LT_LOWEST_LATENCY.
}
// https://github.com/MicrosoftDocs/sdk-api/blob/docs/sdk-api-src/content/winnt/ns-winnt-battery_reporting_scale.md
public struct BATTERY_REPORTING_SCALE
{
public UInt32 Granularity;
public UInt32 Capacity;
}
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-system_power_state
public enum SYSTEM_POWER_STATE
{
PowerSystemUnspecified = 0, //Unspecified system power state.
PowerSystemWorking = 1, //Specifies system power state S0.
PowerSystemSleeping1 = 2, //Specifies system power state S1.
PowerSystemSleeping2 = 3, //Specifies system power state S2.
PowerSystemSleeping3 = 4, //Specifies system power state S3.
PowerSystemHibernate = 5, //Specifies system power state S4 (HIBERNATE).
PowerSystemShutdown = 6, //Specifies system power state S5 (OFF).
PowerSystemMaximum = 7 //Specifies the maximum enumeration value.
}
}
"@
[PowerCfg]::GetCapabilities()
}
用法:
PS C:WINDOWSsystem32> Get-PowerCapabilities
PowerButtonPresent : True
SleepButtonPresent : True
LidPresent : True
SystemS1 : False
SystemS2 : False
SystemS3 : True
SystemS4 : True
SystemS5 : True
HiberFilePresent : True
FullWake : True
VideoDimPresent : True
ApmPresent : False
UpsPresent : False
ThermalControl : True
ProcessorThrottle : False
ProcessorMinThrottle : 0
ProcessorMaxThrottle : 0
FastSystemS4 : True
Hiberboot : True
WakeAlarmPresent : False
AoAc : False
spare2 : {0, 2, 0}
DiskSpinDown : False
HiberFileType : 0
AoAcConnectivitySupported : False
spare3 : {0, 0, 0, 1...}
SystemBatteriesPresent : False
BatteriesAreShortTerm : False
BatteryScale : {PowerCfg7+BATTERY_REPORTING_SCALE, PowerCfg7+BATTERY_REPORTING_SCALE,
PowerCfg7+BATTERY_REPORTING_SCALE}
AcOnLineWake : PowerSystemHibernate
SoftLidWake : PowerSystemUnspecified
RtcWake : PowerSystemUnspecified
MinDeviceWakeState : PowerSystemUnspecified
DefaultLowLatencyWake : PowerSystemUnspecified
我不确定BatteryScale是否准确,因为它为我返回了全部0。所有PowerSystemUnspecified值也有点令人担忧。但S0-5睡眠状态似乎都报告正确。