Jump to content
Sign in to follow this  
LVAC

Get threads of a specify process

Recommended Posts

LVAC

I found on this forum a UDF for Enumarating Threads

But that UDF enumarates all threads of all processes. I want to get threads of a specify process (not all processes). Can you help me?

Share this post


Link to post
Share on other sites
Andreik

I found something on forum. Use _GetAllProcessThreads with PID of your process.

#include <WinAPi.au3>
#include <Array.au3>

Global Const $TH32CS_SNAPTHREAD = 0x00000004
Global Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;"

Func _GetAllProcessThreads($iPid)
    Local $call = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    Local $handle = $call[0]
    Local $RetArr[1][3]
;~     ConsoleWrite("Handle: " & $handle & @CRLF)
    Local $te32 = DllStructCreate($THREADENTRY32)
    DllStructSetData($te32, "dwSize", DllStructGetSize($te32))
    $call = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $handle, "ptr", DllStructGetPtr($te32))
    If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32)
    Do
        $call = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $handle, "ptr", DllStructGetPtr($te32))
        If Not $call[0] Then ExitLoop
        If DllStructGetData($te32, "th32OwnerProcessID") = $iPid Then _GetAllThreads_ArrHelper($RetArr, $te32)
    Until True And False
    _ArrayDelete($RetArr, 0)
    _WinAPI_CloseHandle($handle)
    Return $RetArr
EndFunc   ;==>_GetAllProcessThreads

Func _GetAllThreads_ArrHelper(ByRef $arr, $TE32_Struct)
    Local $ub = UBound($arr)
    ReDim $arr[$ub + 1][3]
    $arr[$ub][0] = DllStructGetData($TE32_Struct, "th32ThreadId")
    $arr[$ub][1] = DllStructGetData($TE32_Struct, "th32OwnerProcessID")
    $arr[$ub][2] = DllStructGetData($TE32_Struct, "tpBasePri")
EndFunc   ;==>_GetAllThreads_ArrHelper

When the words fail... music speaks

Share this post


Link to post
Share on other sites
LVAC

Oh no! I found that the array displayed when use Arraydisplay() is all way have only [0] row >_

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.