-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathEnumerateChildProcesses.ahk
38 lines (35 loc) · 1.1 KB
/
EnumerateChildProcesses.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
/*
#NoEnv
#Persistent
SetBatchLines, -1
Run, firefox,,, PID
timer := Func("SetChildProcessesPriority").Bind([PID], "H")
SetTimer, % timer, 5000
Return
SetChildProcessesPriority(PidArray, priority) {
static changed := []
for k, PID in PidArray {
if !changed.HasKey(PID) {
Process, Priority, % PID, % priority
changed[PID] := ""
}
if (arr := EnumerateChilds(PID))
SetChildProcessesPriority(arr, priority)
}
}
*/
EnumerateChilds(PID) {
static MAX_PATH := 260
childs := []
hSnap := DllCall("CreateToolhelp32Snapshot", UInt, TH32CS_SNAPPROCESS := 2, UInt, 0, Ptr)
VarSetCapacity(PROCESSENTRY32, sz := 4*7 + A_PtrSize*2 + MAX_PATH << !!A_IsUnicode, 0)
NumPut(sz, PROCESSENTRY32, "UInt")
DllCall("Process32First", Ptr, hSnap, Ptr, &PROCESSENTRY32)
Loop {
parentPID := NumGet(PROCESSENTRY32, 4*4 + A_PtrSize*2, "UInt")
if (parentPID = PID)
childs.Push( NumGet(PROCESSENTRY32, 4*2, "UInt") )
} until !DllCall("Process32Next", Ptr, hSnap, Ptr, &PROCESSENTRY32)
DllCall("CloseHandle", Ptr, hSnap)
Return childs[1] ? childs : ""
}