ホーム › System.Power › POWER_POLICY
POWER_POLICY
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| user | USER_POWER_POLICY | 80 | +0 | +0 | ユーザー単位の電源ポリシー(USER_POWER_POLICY)である。 |
| mach | MACHINE_POWER_POLICY | 64 | +80 | +80 | マシン単位の電源ポリシー(MACHINE_POWER_POLICY)である。 |
各言語での定義
#include <windows.h>
// POWER_ACTION_POLICY (x64 12 / x86 12 バイト)
typedef struct POWER_ACTION_POLICY {
POWER_ACTION Action;
DWORD Flags;
POWER_ACTION_POLICY_EVENT_CODE EventCode;
} POWER_ACTION_POLICY;
// USER_POWER_POLICY (x64 80 / x86 80 バイト)
typedef struct USER_POWER_POLICY {
DWORD Revision;
POWER_ACTION_POLICY IdleAc;
POWER_ACTION_POLICY IdleDc;
DWORD IdleTimeoutAc;
DWORD IdleTimeoutDc;
BYTE IdleSensitivityAc;
BYTE IdleSensitivityDc;
BYTE ThrottlePolicyAc;
BYTE ThrottlePolicyDc;
SYSTEM_POWER_STATE MaxSleepAc;
SYSTEM_POWER_STATE MaxSleepDc;
DWORD Reserved[2];
DWORD VideoTimeoutAc;
DWORD VideoTimeoutDc;
DWORD SpindownTimeoutAc;
DWORD SpindownTimeoutDc;
BOOLEAN OptimizeForPowerAc;
BOOLEAN OptimizeForPowerDc;
BYTE FanThrottleToleranceAc;
BYTE FanThrottleToleranceDc;
BYTE ForcedThrottleAc;
BYTE ForcedThrottleDc;
} USER_POWER_POLICY;
// MACHINE_POWER_POLICY (x64 64 / x86 64 バイト)
typedef struct MACHINE_POWER_POLICY {
DWORD Revision;
SYSTEM_POWER_STATE MinSleepAc;
SYSTEM_POWER_STATE MinSleepDc;
SYSTEM_POWER_STATE ReducedLatencySleepAc;
SYSTEM_POWER_STATE ReducedLatencySleepDc;
DWORD DozeTimeoutAc;
DWORD DozeTimeoutDc;
DWORD DozeS4TimeoutAc;
DWORD DozeS4TimeoutDc;
BYTE MinThrottleAc;
BYTE MinThrottleDc;
BYTE pad1[2];
POWER_ACTION_POLICY OverThrottledAc;
POWER_ACTION_POLICY OverThrottledDc;
} MACHINE_POWER_POLICY;
// POWER_POLICY (x64 144 / x86 144 バイト)
typedef struct POWER_POLICY {
USER_POWER_POLICY user;
MACHINE_POWER_POLICY mach;
} POWER_POLICY;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct POWER_ACTION_POLICY
{
public int Action;
public uint Flags;
public uint EventCode;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_POWER_POLICY
{
public uint Revision;
public POWER_ACTION_POLICY IdleAc;
public POWER_ACTION_POLICY IdleDc;
public uint IdleTimeoutAc;
public uint IdleTimeoutDc;
public byte IdleSensitivityAc;
public byte IdleSensitivityDc;
public byte ThrottlePolicyAc;
public byte ThrottlePolicyDc;
public int MaxSleepAc;
public int MaxSleepDc;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public uint[] Reserved;
public uint VideoTimeoutAc;
public uint VideoTimeoutDc;
public uint SpindownTimeoutAc;
public uint SpindownTimeoutDc;
[MarshalAs(UnmanagedType.U1)] public bool OptimizeForPowerAc;
[MarshalAs(UnmanagedType.U1)] public bool OptimizeForPowerDc;
public byte FanThrottleToleranceAc;
public byte FanThrottleToleranceDc;
public byte ForcedThrottleAc;
public byte ForcedThrottleDc;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MACHINE_POWER_POLICY
{
public uint Revision;
public int MinSleepAc;
public int MinSleepDc;
public int ReducedLatencySleepAc;
public int ReducedLatencySleepDc;
public uint DozeTimeoutAc;
public uint DozeTimeoutDc;
public uint DozeS4TimeoutAc;
public uint DozeS4TimeoutDc;
public byte MinThrottleAc;
public byte MinThrottleDc;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] pad1;
public POWER_ACTION_POLICY OverThrottledAc;
public POWER_ACTION_POLICY OverThrottledDc;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct POWER_POLICY
{
public USER_POWER_POLICY user;
public MACHINE_POWER_POLICY mach;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure POWER_ACTION_POLICY
Public Action As Integer
Public Flags As UInteger
Public EventCode As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure USER_POWER_POLICY
Public Revision As UInteger
Public IdleAc As POWER_ACTION_POLICY
Public IdleDc As POWER_ACTION_POLICY
Public IdleTimeoutAc As UInteger
Public IdleTimeoutDc As UInteger
Public IdleSensitivityAc As Byte
Public IdleSensitivityDc As Byte
Public ThrottlePolicyAc As Byte
Public ThrottlePolicyDc As Byte
Public MaxSleepAc As Integer
Public MaxSleepDc As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public Reserved() As UInteger
Public VideoTimeoutAc As UInteger
Public VideoTimeoutDc As UInteger
Public SpindownTimeoutAc As UInteger
Public SpindownTimeoutDc As UInteger
<MarshalAs(UnmanagedType.U1)> Public OptimizeForPowerAc As Boolean
<MarshalAs(UnmanagedType.U1)> Public OptimizeForPowerDc As Boolean
Public FanThrottleToleranceAc As Byte
Public FanThrottleToleranceDc As Byte
Public ForcedThrottleAc As Byte
Public ForcedThrottleDc As Byte
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MACHINE_POWER_POLICY
Public Revision As UInteger
Public MinSleepAc As Integer
Public MinSleepDc As Integer
Public ReducedLatencySleepAc As Integer
Public ReducedLatencySleepDc As Integer
Public DozeTimeoutAc As UInteger
Public DozeTimeoutDc As UInteger
Public DozeS4TimeoutAc As UInteger
Public DozeS4TimeoutDc As UInteger
Public MinThrottleAc As Byte
Public MinThrottleDc As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public pad1() As Byte
Public OverThrottledAc As POWER_ACTION_POLICY
Public OverThrottledDc As POWER_ACTION_POLICY
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure POWER_POLICY
Public user As USER_POWER_POLICY
Public mach As MACHINE_POWER_POLICY
End Structureimport ctypes
from ctypes import wintypes
class POWER_ACTION_POLICY(ctypes.Structure):
_fields_ = [
("Action", ctypes.c_int),
("Flags", wintypes.DWORD),
("EventCode", wintypes.DWORD),
]
class USER_POWER_POLICY(ctypes.Structure):
_fields_ = [
("Revision", wintypes.DWORD),
("IdleAc", POWER_ACTION_POLICY),
("IdleDc", POWER_ACTION_POLICY),
("IdleTimeoutAc", wintypes.DWORD),
("IdleTimeoutDc", wintypes.DWORD),
("IdleSensitivityAc", ctypes.c_ubyte),
("IdleSensitivityDc", ctypes.c_ubyte),
("ThrottlePolicyAc", ctypes.c_ubyte),
("ThrottlePolicyDc", ctypes.c_ubyte),
("MaxSleepAc", ctypes.c_int),
("MaxSleepDc", ctypes.c_int),
("Reserved", wintypes.DWORD * 2),
("VideoTimeoutAc", wintypes.DWORD),
("VideoTimeoutDc", wintypes.DWORD),
("SpindownTimeoutAc", wintypes.DWORD),
("SpindownTimeoutDc", wintypes.DWORD),
("OptimizeForPowerAc", ctypes.c_byte),
("OptimizeForPowerDc", ctypes.c_byte),
("FanThrottleToleranceAc", ctypes.c_ubyte),
("FanThrottleToleranceDc", ctypes.c_ubyte),
("ForcedThrottleAc", ctypes.c_ubyte),
("ForcedThrottleDc", ctypes.c_ubyte),
]
class MACHINE_POWER_POLICY(ctypes.Structure):
_fields_ = [
("Revision", wintypes.DWORD),
("MinSleepAc", ctypes.c_int),
("MinSleepDc", ctypes.c_int),
("ReducedLatencySleepAc", ctypes.c_int),
("ReducedLatencySleepDc", ctypes.c_int),
("DozeTimeoutAc", wintypes.DWORD),
("DozeTimeoutDc", wintypes.DWORD),
("DozeS4TimeoutAc", wintypes.DWORD),
("DozeS4TimeoutDc", wintypes.DWORD),
("MinThrottleAc", ctypes.c_ubyte),
("MinThrottleDc", ctypes.c_ubyte),
("pad1", ctypes.c_ubyte * 2),
("OverThrottledAc", POWER_ACTION_POLICY),
("OverThrottledDc", POWER_ACTION_POLICY),
]
class POWER_POLICY(ctypes.Structure):
_fields_ = [
("user", USER_POWER_POLICY),
("mach", MACHINE_POWER_POLICY),
]#[repr(C)]
pub struct POWER_ACTION_POLICY {
pub Action: i32,
pub Flags: u32,
pub EventCode: u32,
}
#[repr(C)]
pub struct USER_POWER_POLICY {
pub Revision: u32,
pub IdleAc: POWER_ACTION_POLICY,
pub IdleDc: POWER_ACTION_POLICY,
pub IdleTimeoutAc: u32,
pub IdleTimeoutDc: u32,
pub IdleSensitivityAc: u8,
pub IdleSensitivityDc: u8,
pub ThrottlePolicyAc: u8,
pub ThrottlePolicyDc: u8,
pub MaxSleepAc: i32,
pub MaxSleepDc: i32,
pub Reserved: [u32; 2],
pub VideoTimeoutAc: u32,
pub VideoTimeoutDc: u32,
pub SpindownTimeoutAc: u32,
pub SpindownTimeoutDc: u32,
pub OptimizeForPowerAc: u8,
pub OptimizeForPowerDc: u8,
pub FanThrottleToleranceAc: u8,
pub FanThrottleToleranceDc: u8,
pub ForcedThrottleAc: u8,
pub ForcedThrottleDc: u8,
}
#[repr(C)]
pub struct MACHINE_POWER_POLICY {
pub Revision: u32,
pub MinSleepAc: i32,
pub MinSleepDc: i32,
pub ReducedLatencySleepAc: i32,
pub ReducedLatencySleepDc: i32,
pub DozeTimeoutAc: u32,
pub DozeTimeoutDc: u32,
pub DozeS4TimeoutAc: u32,
pub DozeS4TimeoutDc: u32,
pub MinThrottleAc: u8,
pub MinThrottleDc: u8,
pub pad1: [u8; 2],
pub OverThrottledAc: POWER_ACTION_POLICY,
pub OverThrottledDc: POWER_ACTION_POLICY,
}
#[repr(C)]
pub struct POWER_POLICY {
pub user: USER_POWER_POLICY,
pub mach: MACHINE_POWER_POLICY,
}import "golang.org/x/sys/windows"
type POWER_ACTION_POLICY struct {
Action int32
Flags uint32
EventCode uint32
}
type USER_POWER_POLICY struct {
Revision uint32
IdleAc POWER_ACTION_POLICY
IdleDc POWER_ACTION_POLICY
IdleTimeoutAc uint32
IdleTimeoutDc uint32
IdleSensitivityAc byte
IdleSensitivityDc byte
ThrottlePolicyAc byte
ThrottlePolicyDc byte
MaxSleepAc int32
MaxSleepDc int32
Reserved [2]uint32
VideoTimeoutAc uint32
VideoTimeoutDc uint32
SpindownTimeoutAc uint32
SpindownTimeoutDc uint32
OptimizeForPowerAc byte
OptimizeForPowerDc byte
FanThrottleToleranceAc byte
FanThrottleToleranceDc byte
ForcedThrottleAc byte
ForcedThrottleDc byte
}
type MACHINE_POWER_POLICY struct {
Revision uint32
MinSleepAc int32
MinSleepDc int32
ReducedLatencySleepAc int32
ReducedLatencySleepDc int32
DozeTimeoutAc uint32
DozeTimeoutDc uint32
DozeS4TimeoutAc uint32
DozeS4TimeoutDc uint32
MinThrottleAc byte
MinThrottleDc byte
pad1 [2]byte
OverThrottledAc POWER_ACTION_POLICY
OverThrottledDc POWER_ACTION_POLICY
}
type POWER_POLICY struct {
user USER_POWER_POLICY
mach MACHINE_POWER_POLICY
}type
POWER_ACTION_POLICY = record
Action: Integer;
Flags: DWORD;
EventCode: DWORD;
end;
USER_POWER_POLICY = record
Revision: DWORD;
IdleAc: POWER_ACTION_POLICY;
IdleDc: POWER_ACTION_POLICY;
IdleTimeoutAc: DWORD;
IdleTimeoutDc: DWORD;
IdleSensitivityAc: Byte;
IdleSensitivityDc: Byte;
ThrottlePolicyAc: Byte;
ThrottlePolicyDc: Byte;
MaxSleepAc: Integer;
MaxSleepDc: Integer;
Reserved: array[0..1] of DWORD;
VideoTimeoutAc: DWORD;
VideoTimeoutDc: DWORD;
SpindownTimeoutAc: DWORD;
SpindownTimeoutDc: DWORD;
OptimizeForPowerAc: ByteBool;
OptimizeForPowerDc: ByteBool;
FanThrottleToleranceAc: Byte;
FanThrottleToleranceDc: Byte;
ForcedThrottleAc: Byte;
ForcedThrottleDc: Byte;
end;
MACHINE_POWER_POLICY = record
Revision: DWORD;
MinSleepAc: Integer;
MinSleepDc: Integer;
ReducedLatencySleepAc: Integer;
ReducedLatencySleepDc: Integer;
DozeTimeoutAc: DWORD;
DozeTimeoutDc: DWORD;
DozeS4TimeoutAc: DWORD;
DozeS4TimeoutDc: DWORD;
MinThrottleAc: Byte;
MinThrottleDc: Byte;
pad1: array[0..1] of Byte;
OverThrottledAc: POWER_ACTION_POLICY;
OverThrottledDc: POWER_ACTION_POLICY;
end;
POWER_POLICY = record
user: USER_POWER_POLICY;
mach: MACHINE_POWER_POLICY;
end;const POWER_ACTION_POLICY = extern struct {
Action: i32,
Flags: u32,
EventCode: u32,
};
const USER_POWER_POLICY = extern struct {
Revision: u32,
IdleAc: POWER_ACTION_POLICY,
IdleDc: POWER_ACTION_POLICY,
IdleTimeoutAc: u32,
IdleTimeoutDc: u32,
IdleSensitivityAc: u8,
IdleSensitivityDc: u8,
ThrottlePolicyAc: u8,
ThrottlePolicyDc: u8,
MaxSleepAc: i32,
MaxSleepDc: i32,
Reserved: [2]u32,
VideoTimeoutAc: u32,
VideoTimeoutDc: u32,
SpindownTimeoutAc: u32,
SpindownTimeoutDc: u32,
OptimizeForPowerAc: u8,
OptimizeForPowerDc: u8,
FanThrottleToleranceAc: u8,
FanThrottleToleranceDc: u8,
ForcedThrottleAc: u8,
ForcedThrottleDc: u8,
};
const MACHINE_POWER_POLICY = extern struct {
Revision: u32,
MinSleepAc: i32,
MinSleepDc: i32,
ReducedLatencySleepAc: i32,
ReducedLatencySleepDc: i32,
DozeTimeoutAc: u32,
DozeTimeoutDc: u32,
DozeS4TimeoutAc: u32,
DozeS4TimeoutDc: u32,
MinThrottleAc: u8,
MinThrottleDc: u8,
pad1: [2]u8,
OverThrottledAc: POWER_ACTION_POLICY,
OverThrottledDc: POWER_ACTION_POLICY,
};
const POWER_POLICY = extern struct {
user: USER_POWER_POLICY,
mach: MACHINE_POWER_POLICY,
};type
POWER_ACTION_POLICY {.bycopy.} = object
Action: int32
Flags: uint32
EventCode: uint32
USER_POWER_POLICY {.bycopy.} = object
Revision: uint32
IdleAc: POWER_ACTION_POLICY
IdleDc: POWER_ACTION_POLICY
IdleTimeoutAc: uint32
IdleTimeoutDc: uint32
IdleSensitivityAc: uint8
IdleSensitivityDc: uint8
ThrottlePolicyAc: uint8
ThrottlePolicyDc: uint8
MaxSleepAc: int32
MaxSleepDc: int32
Reserved: array[2, uint32]
VideoTimeoutAc: uint32
VideoTimeoutDc: uint32
SpindownTimeoutAc: uint32
SpindownTimeoutDc: uint32
OptimizeForPowerAc: uint8
OptimizeForPowerDc: uint8
FanThrottleToleranceAc: uint8
FanThrottleToleranceDc: uint8
ForcedThrottleAc: uint8
ForcedThrottleDc: uint8
MACHINE_POWER_POLICY {.bycopy.} = object
Revision: uint32
MinSleepAc: int32
MinSleepDc: int32
ReducedLatencySleepAc: int32
ReducedLatencySleepDc: int32
DozeTimeoutAc: uint32
DozeTimeoutDc: uint32
DozeS4TimeoutAc: uint32
DozeS4TimeoutDc: uint32
MinThrottleAc: uint8
MinThrottleDc: uint8
pad1: array[2, uint8]
OverThrottledAc: POWER_ACTION_POLICY
OverThrottledDc: POWER_ACTION_POLICY
POWER_POLICY {.bycopy.} = object
user: USER_POWER_POLICY
mach: MACHINE_POWER_POLICYstruct POWER_ACTION_POLICY
{
int Action;
uint Flags;
uint EventCode;
}
struct USER_POWER_POLICY
{
uint Revision;
POWER_ACTION_POLICY IdleAc;
POWER_ACTION_POLICY IdleDc;
uint IdleTimeoutAc;
uint IdleTimeoutDc;
ubyte IdleSensitivityAc;
ubyte IdleSensitivityDc;
ubyte ThrottlePolicyAc;
ubyte ThrottlePolicyDc;
int MaxSleepAc;
int MaxSleepDc;
uint[2] Reserved;
uint VideoTimeoutAc;
uint VideoTimeoutDc;
uint SpindownTimeoutAc;
uint SpindownTimeoutDc;
ubyte OptimizeForPowerAc;
ubyte OptimizeForPowerDc;
ubyte FanThrottleToleranceAc;
ubyte FanThrottleToleranceDc;
ubyte ForcedThrottleAc;
ubyte ForcedThrottleDc;
}
struct MACHINE_POWER_POLICY
{
uint Revision;
int MinSleepAc;
int MinSleepDc;
int ReducedLatencySleepAc;
int ReducedLatencySleepDc;
uint DozeTimeoutAc;
uint DozeTimeoutDc;
uint DozeS4TimeoutAc;
uint DozeS4TimeoutDc;
ubyte MinThrottleAc;
ubyte MinThrottleDc;
ubyte[2] pad1;
POWER_ACTION_POLICY OverThrottledAc;
POWER_ACTION_POLICY OverThrottledDc;
}
struct POWER_POLICY
{
USER_POWER_POLICY user;
MACHINE_POWER_POLICY mach;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; POWER_POLICY サイズ: 144 バイト(x64)
dim st, 36 ; 4byte整数×36(構造体サイズ 144 / 4 切り上げ)
; user : USER_POWER_POLICY (+0, 80byte) varptr(st)+0 を基点に操作(80byte:入れ子/配列)
; mach : MACHINE_POWER_POLICY (+80, 64byte) varptr(st)+80 を基点に操作(64byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global POWER_ACTION_POLICY
#field int Action
#field int Flags
#field int EventCode
#endstruct
#defstruct global USER_POWER_POLICY
#field int Revision
#field POWER_ACTION_POLICY IdleAc
#field POWER_ACTION_POLICY IdleDc
#field int IdleTimeoutAc
#field int IdleTimeoutDc
#field byte IdleSensitivityAc
#field byte IdleSensitivityDc
#field byte ThrottlePolicyAc
#field byte ThrottlePolicyDc
#field int MaxSleepAc
#field int MaxSleepDc
#field int Reserved 2
#field int VideoTimeoutAc
#field int VideoTimeoutDc
#field int SpindownTimeoutAc
#field int SpindownTimeoutDc
#field bool1 OptimizeForPowerAc
#field bool1 OptimizeForPowerDc
#field byte FanThrottleToleranceAc
#field byte FanThrottleToleranceDc
#field byte ForcedThrottleAc
#field byte ForcedThrottleDc
#endstruct
#defstruct global MACHINE_POWER_POLICY
#field int Revision
#field int MinSleepAc
#field int MinSleepDc
#field int ReducedLatencySleepAc
#field int ReducedLatencySleepDc
#field int DozeTimeoutAc
#field int DozeTimeoutDc
#field int DozeS4TimeoutAc
#field int DozeS4TimeoutDc
#field byte MinThrottleAc
#field byte MinThrottleDc
#field byte pad1 2
#field POWER_ACTION_POLICY OverThrottledAc
#field POWER_ACTION_POLICY OverThrottledDc
#endstruct
#defstruct global POWER_POLICY
#field USER_POWER_POLICY user
#field MACHINE_POWER_POLICY mach
#endstruct
stdim st, POWER_POLICY ; NSTRUCT 変数を確保