-
Notifications
You must be signed in to change notification settings - Fork 8
/
SystemProcessorInformation.ahk
54 lines (43 loc) · 2.3 KB
/
SystemProcessorInformation.ahk
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
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-12-22
; Modified ......: 2023-01-13
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: SystemProcessorInformation()
;
; Parameter(s)...: No parameters used
;
; Return ........: Returns a SYSTEM_PROCESSOR_INFORMATION structure from the NtQuerySystemInformation function.
; =============================================================================================================================================================
#Requires AutoHotkey v2.0
SystemProcessorInformation()
{
#DllLoad "ntdll.dll"
static STATUS_SUCCESS := 0x00000000
static STATUS_INFO_LENGTH_MISMATCH := 0xC0000004
static STATUS_BUFFER_TOO_SMALL := 0xC0000023
static SYSTEM_PROCESSOR_INFORMATION := 0x00000001
Buf := Buffer(0x000C)
NT_STATUS := DllCall("ntdll\NtQuerySystemInformation", "Int", SYSTEM_PROCESSOR_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_INFORMATION, "Ptr", Buf.Ptr, "UInt", Buf.Size, "UInt*", &Size := 0, "UInt")
}
if (NT_STATUS = STATUS_SUCCESS)
{
PROCESSOR_INFORMATION := Map()
PROCESSOR_INFORMATION["ProcessorArchitecture"] := NumGet(Buf, 0x0000, "UShort")
PROCESSOR_INFORMATION["ProcessorLevel"] := NumGet(Buf, 0x0002, "UShort")
PROCESSOR_INFORMATION["ProcessorRevision"] := NumGet(Buf, 0x0004, "UShort")
PROCESSOR_INFORMATION["MaximumProcessors"] := NumGet(Buf, 0x0006, "UShort")
PROCESSOR_INFORMATION["ProcessorFeatureBits"] := NumGet(Buf, 0x0008, "UInt")
return PROCESSOR_INFORMATION
}
throw OSError()
}
; =============================================================================================================================================================
; Example
; =============================================================================================================================================================
MsgBox SystemProcessorInformation()["MaximumProcessors"]