Code: Select all
Procedure GetProcessChildIDs(ParentID, List __out_ChildIDs())
Protected Entry.PROCESSENTRY32
Protected hSnapshot
NewList ChildIDs()
Entry\dwSize=SizeOf(PROCESSENTRY32)
hSnapshot=CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS,0)
If hSnapshot=#INVALID_HANDLE_VALUE
ProcedureReturn #False
EndIf
If Not Process32First_(hSnapshot,@Entry)
ProcedureReturn #False
EndIf
Repeat
If Entry\th32ParentProcessID=ParentID
AddElement(__out_ChildIDs())
__out_ChildIDs()=Entry\th32ProcessID
;/ Don't enumerate the idle process (id 0)
If Entry\th32ProcessID
GetProcessChildIDs(Entry\th32ProcessID,ChildIDs())
EndIf
ForEach ChildIDs()
AddElement(__out_ChildIDs())
__out_ChildIDs()=ChildIDs()
Next
EndIf
Until Not Process32Next_(hSnapshot,@Entry)
CloseHandle_(hSnapshot)
ProcedureReturn #True
EndProcedure