Repository navigation
Expand file tree
/
Copy pathSystemProcessorPowerInformation.ahk
More file actions
69 lines (58 loc) · 3.75 KB
/
Copy pathSystemProcessorPowerInformation.ahk
File metadata and controls
69 lines (58 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-12-22
; Modified ......: 2023-01-13
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: SystemProcessorPowerInformation()
;
; Parameter(s)...: No parameters used
;
; Return ........: Returns a SYSTEM_PROCESSOR_POWER_INFORMATION structure from the NtQuerySystemInformation function.
; =============================================================================================================================================================
#Requires AutoHotkey v2.0
SystemProcessorPowerInformation()
{
#DllLoad "ntdll.dll"
static STATUS_SUCCESS := 0x00000000
static STATUS_INFO_LENGTH_MISMATCH := 0xC0000004
static STATUS_BUFFER_TOO_SMALL := 0xC0000023
static SYSTEM_PROCESSOR_POWER_INFORMATION := 0x0000003D
Buf := Buffer(0x0050)
NT_STATUS := DllCall("ntdll\NtQuerySystemInformation", "Int", SYSTEM_PROCESSOR_POWER_INFORMATION, "Ptr", Buf.Ptr, "UInt", Buf.Size, "UInt*", &Size := 0, "UInt")
while (NT_STATUS = STATUS_INFO_LENGTH_MISMATCH) || (NT_STATUS = STATUS_BUFFER_TOO_SMALL)
{
Buf := Buffer(Size)
NT_STATUS := DllCall("ntdll\NtQuerySystemInformation", "Int", SYSTEM_PROCESSOR_POWER_INFORMATION, "Ptr", Buf.Ptr, "UInt", Buf.Size, "UInt*", &Size := 0, "UInt")
}
if (NT_STATUS = STATUS_SUCCESS)
{
PROCESSOR_POWER_INFORMATION := Map()
PROCESSOR_POWER_INFORMATION["CurrentFrequency"] := NumGet(Buf, 0x0000, "UChar")
PROCESSOR_POWER_INFORMATION["ThermalLimitFrequency"] := NumGet(Buf, 0x0001, "UChar")
PROCESSOR_POWER_INFORMATION["ConstantThrottleFrequency"] := NumGet(Buf, 0x0002, "UChar")
PROCESSOR_POWER_INFORMATION["DegradedThrottleFrequency"] := NumGet(Buf, 0x0003, "UChar")
PROCESSOR_POWER_INFORMATION["LastBusyFrequency"] := NumGet(Buf, 0x0004, "UChar")
PROCESSOR_POWER_INFORMATION["LastC3Frequency"] := NumGet(Buf, 0x0005, "UChar")
PROCESSOR_POWER_INFORMATION["LastAdjustedBusyFrequency"] := NumGet(Buf, 0x0006, "UChar")
PROCESSOR_POWER_INFORMATION["ProcessorMinThrottle"] := NumGet(Buf, 0x0007, "UChar")
PROCESSOR_POWER_INFORMATION["ProcessorMaxThrottle"] := NumGet(Buf, 0x0008, "UChar")
PROCESSOR_POWER_INFORMATION["NumberOfFrequencies"] := NumGet(Buf, 0x000C, "UInt")
PROCESSOR_POWER_INFORMATION["PromotionCount"] := NumGet(Buf, 0x0010, "UInt")
PROCESSOR_POWER_INFORMATION["DemotionCount"] := NumGet(Buf, 0x0014, "UInt")
PROCESSOR_POWER_INFORMATION["ErrorCount"] := NumGet(Buf, 0x0018, "UInt")
PROCESSOR_POWER_INFORMATION["RetryCount"] := NumGet(Buf, 0x001C, "UInt")
PROCESSOR_POWER_INFORMATION["CurrentFrequencyTime"] := NumGet(Buf, 0x0020, "UInt64")
PROCESSOR_POWER_INFORMATION["CurrentProcessorTime"] := NumGet(Buf, 0x0028, "UInt64")
PROCESSOR_POWER_INFORMATION["CurrentProcessorIdleTime"] := NumGet(Buf, 0x0030, "UInt64")
PROCESSOR_POWER_INFORMATION["LastProcessorTime"] := NumGet(Buf, 0x0038, "UInt64")
PROCESSOR_POWER_INFORMATION["LastProcessorIdleTime"] := NumGet(Buf, 0x0040, "UInt64")
PROCESSOR_POWER_INFORMATION["Energy"] := NumGet(Buf, 0x0048, "UInt64")
return PROCESSOR_POWER_INFORMATION
}
throw OSError()
}
; =============================================================================================================================================================
; Example
; =============================================================================================================================================================
MsgBox SystemProcessorPowerInformation()["CurrentFrequency"]