;~ #include<WinAPIEx.au3>
Local $PID
$PID = Run(@ComSpec & ' /c ' & 'notepad')
Sleep(500)
Local $pList=ProcessList(),$sProcParent="Родительский процесс "&$PID&" имеет следующие дочерние процессы:"&@CRLF
For $i=1 To $pList[0][0]
Local $pi=_WinAPI_GetParentProcess($pList[$i][1])
If $pi=$PID Then
$sProcParent&=$pList[$i][1]&" - "&$pList[$i][0]&@CRLF
EndIf
Next
$sProcParent=StringStripWS($sProcParent,2)
MsgBox(0,'',$sProcParent)
Func _WinAPI_GetParentProcess($PID = 0)
If Not $PID Then
$PID = @AutoItPID
EndIf
Local $hSnapshot = DllCall('kernel32.dll', 'ptr', 'CreateToolhelp32Snapshot', 'dword', 0x00000002, 'dword', 0)
If (@error) Or (Not $hSnapshot[0]) Then
Return SetError(1, 0, 0)
EndIf
Local $tPROCESSENTRY32 = DllStructCreate('dword Size;dword Usage;dword ProcessID;ulong_ptr DefaultHeapID;dword ModuleID;dword Threads;dword ParentProcessID;long PriClassBase;dword Flags;wchar ExeFile[260]')
Local $pPROCESSENTRY32 = DllStructGetPtr($tPROCESSENTRY32)
Local $Ret, $Result = 0
$hSnapshot = $hSnapshot[0]
DllStructSetData($tPROCESSENTRY32, 'Size', DllStructGetSize($tPROCESSENTRY32))
$Ret = DllCall('kernel32.dll', 'int', 'Process32FirstW', 'ptr', $hSnapshot, 'ptr', $pPROCESSENTRY32)
While (Not @error) And ($Ret[0])
If DllStructGetData($tPROCESSENTRY32, 'ProcessID') = $PID Then
$Result = DllStructGetData($tPROCESSENTRY32, 'ParentProcessID')
ExitLoop
EndIf
$Ret = DllCall('kernel32.dll', 'int', 'Process32NextW', 'ptr', $hSnapshot, 'ptr', $pPROCESSENTRY32)
WEnd
_WinAPI_CloseHandle($hSnapshot)
If Not $Result Then
Return SetError(1, 0, 0)
EndIf
Return $Result
EndFunc
Func _WinAPI_CloseHandle($hObject)
Local $aResult = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hObject)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0]
EndFunc