Page 1 of 1
enumerate threads
Posted: Tue Jun 01, 2004 11:16 pm
by tonnelier
I know how to enumerate processes (createtollhelpsnapshot, etc...)
But how can i enumerate threads, and know for a given thread, to which process it is attached?
thank for responses
Posted: Wed Jun 02, 2004 4:18 pm
by tonnelier

Stupid i am!!
I've not seen that there are thread32first, thread32next functions too.
So the problem is solved.
Posted: Wed Jun 02, 2004 6:42 pm
by fweil
...,
Because you found ToolHelp.dll exists you are not stupid !
Posted: Wed Jun 02, 2004 8:08 pm
by tonnelier
thanks for this little recomfort!
I've asked earlier if it was possible to pause a process.
Eventually, it's possible, simply by using suspendthread_ for all threads attached to the process. Works fine. (and resumethread_ too)
(If i don't mistake, even if a process don't explicitly create a thread, there is a primary thread attached to it. Threads are the entities, above processes, with which the system manages for the access to the processor)
Posted: Wed Jun 02, 2004 9:16 pm
by fweil
Maybe you scattered me with this DLL ...
HELP me in finding the args to throw in this dll ... I can't find the way to access it well ...
Rgrds
Posted: Thu Jun 03, 2004 12:09 pm
by tonnelier
Here is a procedure to suspend a process whose id is pid:
Code: Select all
Structure thread32
size.l
use.l
idth.l
parentid.l
base.l
delta.l
flags.l
EndStructure
openlibrary(0,"kernel32.dll")
Procedure pause(pid)
thread.thread32
snap = CallFunction (0, "CreateToolhelp32Snapshot",4,0)
If snap
thread\size=SizeOf(thread32)
CallFunction(0,"Thread32First",snap,@thread)
If thread\parentid=pid
h=CallFunction(0,"OpenThread",2,0,thread\idth)
SuspendThread_(h)
CloseHandle_(h)
EndIf
While CallFunction(0,"Thread32Next",snap,@thread)
If thread\parentid=pid
h=CallFunction(0,"OpenThread",2,0,thread\idth)
SuspendThread_(h)
CloseHandle_(h)
EndIf
Wend
EndIf
EndProcedure
and the procedure to resume
Code: Select all
Procedure resume(pid)
thread.thread32
snap = CallFunction (0, "CreateToolhelp32Snapshot",4,0)
If snap
thread\size=SizeOf(thread32)
CallFunction(0,"Thread32First",snap,@thread)
If thread\parentid=pid
h=CallFunction(0,"OpenThread",2,0,thread\idth)
ResumeThread_(h)
CloseHandle_(h)
EndIf
While CallFunction(0,"Thread32Next",snap,@thread)
If thread\parentid=pid
h=CallFunction(0,"OpenThread",2,0,thread\idth)
ResumeThread_(h)
CloseHandle_(h)
EndIf
Wend
EndIf
EndProcedure
for the constants, i use winapi program.
Posted: Mon Apr 11, 2005 12:57 pm
by pvmichael
Thank you very much, this is exactly what i was searching for!