#include-once #include #include Func _ProcessGetChildren($iPID) $iPID = ProcessExists($iPID) If Not $iPID Then Return SetError(1, 0, 0) EndIf Local Const $pgp_TH32CS_SNAPPROCESS = 0x00000002 Local $hK32 = DllOpen("Kernel32.dll") Local $ahToolShot = DllCall($hK32, "handle", "CreateToolhelp32Snapshot", _ "dword", $pgp_TH32CS_SNAPPROCESS, "dword", 0) If @error Or $ahToolShot[0] = -1 Then DllClose($hK32) Return SetError(1, 0, 0) EndIf Local Const $tagPROCESSENTRY32 = _ 'dword dwsize;dword cntUsage;dword th32ProcessID;' & _ 'ulong_ptr th32DefaultHeapID;dword th32ModuleID;' & _ 'dword cntThreads;dword th32ParentProcessID;' & _ 'long pcPriClassBase;dword dwFlags;wchar szExeFile[260]' Local $tPE32 = DllStructCreate($tagPROCESSENTRY32) DllStructSetData($tPE32, "dwsize", DllStructGetSize($tPE32)) Local $aP32First = DllCall($hK32, "bool", "Process32FirstW", _ "dword", $ahToolShot[0], "ptr", DllStructGetPtr($tPE32)) If @error Then _WinAPI_CloseHandle($ahToolShot[0]) DllClose($hK32) Return SetError(2, 0, $iPID) EndIf Local $aRet[10][2], $iCount If DllStructGetData($tPE32, "th32ProcessID") <> $iPID Then If DllStructGetData($tPE32, "th32ParentProcessID") = $iPID Then $iCount += 1 $aRet[0][0] = $iCount $aRet[$iCount][0] = DllStructGetData($tPE32, "szExeFile") $aRet[$iCount][1] = DllStructGetData($tPE32, "th32ParentProcessID") EndIf EndIf Local $aP32Next While 1 $aP32Next = DllCall($hK32, "bool", "Process32NextW", _ "handle", $ahToolShot[0], "ptr", DllStructGetPtr($tPE32)) If @error Or $aP32Next[0] = 0 Then ExitLoop If DllStructGetData($tPE32, "th32ProcessID") <> $iPID Then If DllStructGetData($tPE32, "th32ParentProcessID") = $iPID Then $iCount += 1 If Mod($iCount, 10) = 0 Then ReDim $aRet[$iCount + 10][2] EndIf $aRet[0][0] = $iCount $aRet[$iCount][0] = DllStructGetData($tPE32, "szExeFile") $aRet[$iCount][1] = DllStructGetData($tPE32, "th32ProcessID") EndIf EndIf WEnd _WinAPI_CloseHandle($ahToolShot[0]) DllClose($hK32) If $iCount Then ReDim $aRet[$iCount + 1][2] $aRet[0][0] = $iCount Return $aRet EndIf Return SetError(3, 0, 0) EndFunc ;==>_ProcessGetChildren Func _ProcessGetParent($iPID) $iPID = ProcessExists($iPID) If Not $iPID Then Return SetError(1, 0, 0) EndIf Local $sExeName = _WinAPI_GetProcessName($iPID) Local $aRet[][] = [[1,0],[$sExeName,$iPID]] Local Static $pgp_TH32CS_SNAPPROCESS = 0x00000002 Local $hK32 = DllOpen("Kernel32.dll") Local $ahToolShot = DllCall($hK32, "handle", "CreateToolhelp32Snapshot", _ "dword", $pgp_TH32CS_SNAPPROCESS, "dword", 0) If @error Or $ahToolShot[0] = -1 Then DllClose($hK32) Return SetError(1, 0, $aRet) EndIf Local Static $tagPROCESSENTRY32 = _ 'dword dwsize;dword cntUsage;dword th32ProcessID;' & _ 'ulong_ptr th32DefaultHeapID;dword th32ModuleID;' & _ 'dword cntThreads;dword th32ParentProcessID;' & _ 'long pcPriClassBase;dword dwFlags;wchar szExeFile[260]' Local $tPE32 = DllStructCreate($tagPROCESSENTRY32) Local $pPE32 = DllStructGetPtr($tPE32) DllStructSetData($tPE32, "dwsize", DllStructGetSize($tPE32)) Local $aP32First = DllCall($hK32, "bool", "Process32FirstW", "dword", $ahToolShot[0], "ptr", $pPE32) If @error Then _WinAPI_CloseHandle($ahToolShot[0]) DllClose($hK32) Return SetError(2, 0, $iPID) EndIf Local $iParentID If DllStructGetData($tPE32, "th32ProcessID") = $iPID Then _WinAPI_CloseHandle($ahToolShot[0]) DllClose($hK32) $iParentID = DllStructGetData($tPE32, "th32ParentProcessID") If ProcessExists($iParentID) Then $aRet[1][0] = _WinAPI_GetProcessName($iParentID) $aRet[1][1] = $iParentID EndIf Return $aRet EndIf Local $aP32Next, $iParentID While 1 $aP32Next = DllCall($hK32, "bool", "Process32NextW", "handle", $ahToolShot[0], "ptr", $pPE32) If @error Or $aP32Next[0] = 0 Then ExitLoop If DllStructGetData($tPE32, "th32ProcessID") = $iPID Then $iParentID = DllStructGetData($tPE32, "th32ParentProcessID") If $iParentID <> $iPID Then $aRet[1][0] = _WinAPI_GetProcessName($iParentID) $aRet[1][1] = $iParentID EndIf ExitLoop EndIf WEnd _WinAPI_CloseHandle($ahToolShot[0]) DllClose($hK32) Return $aRet EndFunc;==>_ProcessGetParent ; @param1 = process name or pid ; @param2 = default 0 = drive\etc format ; true = native system path format Func _ProcessGetPathEx($vProcess, $bNative = 0) Local $iPID = ProcessExists($vProcess) If Not $iPID Then ; process does not exist Return SetError(1, 0, "") EndIf Local $szFilePath = "" ; are we working with anything less than vista? Local Static $nWVers = ($__WINVER <> "") ? $__WINVER : __WINVER() If $nWVers < 0x0600 Then ; _WinAPI_GetProcessFileName seems misleading $szFilePath = _WinAPI_GetProcessFileName($iPID) Return SetError(@error, @extended, $szFilePath) EndIf ; vista and above, should help with possible 64bit issues as well Local $hK32 = DllOpen("Kernel32.dll") If @error Or Not $hK32 Then ; could not open kernel32.dll Return SetError(2, 0, 0) EndIf Local Const $pgp_PROCESS_QUERY_LIMITED_INFORMATION = 0x1000 Local Const $pgp_PROCESS_QUERY_INFORMATION = 0x0400 Local Const $pgp_PROCESS_NAME_NATIVE = 0x00000001 ; open process with query info only Local $aOpenProcess = DllCall($hK32, "handle", "OpenProcess", _ "long", BitOR($pgp_PROCESS_QUERY_INFORMATION, _ $pgp_PROCESS_QUERY_LIMITED_INFORMATION), _ "int", 0, "long", $iPID) Local $iErr = @error If $iErr Or Not IsArray($aOpenProcess) Then DllClose($hK32) ; error code from dllcall sent as extended Return SetError(3, $iErr, 0) EndIf Local $hOpenProc = $aOpenProcess[0] Local $nNative = $bNative ? $pgp_PROCESS_NAME_NATIVE : 0 Local $aQuery = DllCall($hK32, "bool", "QueryFullProcessImageNameW", _ "handle", $hOpenProc, "dword", $nNative, "wstr", "", "int*", 4096) $iErr = @error If $iErr Or Not IsArray($aQuery) Then _WinAPI_CloseHandle($hOpenProc) DllClose($hK32) ; error code from dllcall sent as extended Return SetError(4, $iErr, 0) EndIf _WinAPI_CloseHandle($hOpenProc) DllClose($hK32) ; return string length as extended Return SetError(0, $aQuery[4], $aQuery[3]) EndFunc ;==>_ProcessGetPathEx