找回密码
 加入
搜索
查看: 1779|回复: 4

如何查找进程的线程(How to Get ProcessThreads from A PROCESS)

[复制链接]
发表于 2009-4-12 21:04:37 | 显示全部楼层 |阅读模式
如何查找到进程线程进程里的线程
How to Get ProcessThreads from A PROCESS
谢谢高手解答,小弟感谢不尽.


[ 本帖最后由 techbytnt 于 2009-4-14 09:38 编辑 ]
发表于 2009-4-12 21:40:45 | 显示全部楼层
#include <Array.au3>
#include <WinAPI.au3>

Const $TH32CS_SNAPTHREAD = 4
Const $tagThread = "dword dwSize;dword cntUsage;dword th32ThreadID;" & _
                "dword th32OwnerProcessID;long tpBasePri;" & _
                "long tpDeltaPri;dword dwFlags"


$aThread = _EnumProcessThreads(@AutoItPid)
_ArrayDisplay($aThread)



Func _EnumProcessThreads($iProcessId)
        Local $hSnapshot, $iThreadId, $iOwnerId, $tThread, $aResult[1]

        $iProcessId = ProcessExists($iProcessId)
        $tThread = _Thread32First($hSnapshot)
        $hSnapshot = _CreateToolhelp32Snapshot(0, $TH32CS_SNAPTHREAD)

        While True
                _Thread32Next($hSnapshot, $tThread)
                If @error Then ExitLoop
                $iThreadId = DllStructGetData($tThread, "th32ThreadID")
                $iOwnerId = DllStructGetData($tThread, "th32OwnerProcessID")
                If $iOwnerId = $iProcessId Then
                        $aResult[Ubound($aResult) - 1] = $iThreadId
                        Redim $aResult[Ubound($aResult) + 1]
                EndIf
        WEnd
        $tThread = 0
        _WinAPI_CloseHandle($hSnapshot)
        If Ubound($aResult) = 1 Then Return SetError(1, 0, 0)
        Redim $aResult[Ubound($aResult) - 1]
        Return SetError(0, Ubound($aResult), $aResult)
EndFunc        ;==>_EnumProcessThreads()


Func _CreateToolhelp32Snapshot($iProcessId, $iFlag)
        Local $hSnapshot

        $iProcessId = ProcessExists($iProcessId)
        $hSnapshot = DllCall("Kernel32.Dll", "hWnd", "CreateToolhelp32Snapshot", _
                        "dword", $iFlag, "int", $iProcessId)
        Return $hSnapshot[0]
EndFunc        ;==>_CreateToolhelp32Snapshot()

Func _Thread32First($hSnapshot)
        Local $tThread, $pThread, $iResult

        $tThread = DllStructCreate($tagThread)
        $pThread = DllStructGetPtr($tThread)
        DllStructSetData($tThread, 1, DllStructGetSize($tThread))

        $iResult = DllCall("Kernel32.Dll", "int", "Thread32First", _
                        "hWnd", $hSnapshot, _
                        "ptr", $pThread)
        Return SetError(Not $iResult[0], 0, $tThread)
EndFunc        ;==>_Thread32First()


Func _Thread32Next($hSnapshot, ByRef $tThread)
        Local $iResult

        $iResult = DllCall("Kernel32.Dll", "int", "Thread32Next", _
                "hWnd", $hSnapshot, _
                "ptr", DllStructGetPtr($tThread))
        Return SetError(Not $iResult[0], 0, $iResult[0])
EndFunc        ;==>_Thread32Next()
 楼主| 发表于 2009-4-14 09:37:02 | 显示全部楼层
感谢了
发表于 2010-4-20 09:21:40 | 显示全部楼层
高手,感谢了

太需要了
发表于 2012-11-22 16:58:12 | 显示全部楼层
能返回线程的名称吗?如果有的话
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-29 19:28 , Processed in 0.099751 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表