|
-
Jun 15th, 2009, 07:51 AM
#1
Thread Starter
Hyperactive Member
How to enumerate all threads in a process?
Maybe someone can show me how to enumerate all threads in a process?
I know that I should use CreateToolhelp32Snapshot, Process32First, Process32Next and I have made some attempts, but they was unsuccessful. So maybe someone could showe me how to do that correctly?
-
Jun 15th, 2009, 08:06 AM
#2
Fanatic Member
Re: How to enumerate all threads in a process?
-
Jun 15th, 2009, 08:53 AM
#3
Thread Starter
Hyperactive Member
Re: How to enumerate all threads in a process?
 Originally Posted by Dungeon Keeper
Yes, I saw that before, but it doesn't help me much because I don't understand some parts of that code (it is not VB).
-
Jun 15th, 2009, 10:07 AM
#4
Fanatic Member
Re: How to enumerate all threads in a process?
What exactly you don't understand there, ill try to translate it
-
Jun 15th, 2009, 01:26 PM
#5
Thread Starter
Hyperactive Member
Re: How to enumerate all threads in a process?
 Originally Posted by Dungeon Keeper
What exactly you don't understand there, ill try to translate it 
I don't know, this code is missing some things, for example flags for CreateToolhelp32Snapshot and so on. Even if you'll translate this code, it will still be missing huge amount of code and other declarations. So I think that in this case, it is much more clever to write new code in VB from zero.
-
Jun 15th, 2009, 03:40 PM
#6
Fanatic Member
Re: How to enumerate all threads in a process?
In any case you will need to declare those constants, structures and API functions to make it work in VB.
Here are some declarations:
Code:
Declare Function CreateToolhelp32Snapshot Lib "KERNEL32.dll" ( _
ByVal dwFlags As Long, _
ByVal th32ProcessID As Long) As Long
Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long) As Long
Const TH32CS_SNAPTHREAD As Long = &H4
Const INVALID_HANDLE_VALUE As Long = ((Handle) - 1) 'I think this indicates a function failure so you can use 0 for it.
You still need to find declarations for:
FIELD_OFFSET
THREADENTRY32
I have tested it and can guarantee that this code works, it shows process IDs and all thread IDs associated with that process ID, so it does what you need. You will only need to find the process EXE name if you want that too in your process/thread list.
I'm not sure about threads, but i doubt that threads have names - only IDs.
-
Jun 16th, 2009, 09:12 AM
#7
Thread Starter
Hyperactive Member
Re: How to enumerate all threads in a process?
I already have all needed declarations and constants. I just need help with code construction.
-
Jun 17th, 2009, 08:23 AM
#8
Fanatic Member
Re: How to enumerate all threads in a process?
Then code would be:
Code:
Dim h As HANDLE 'or it maybe could be Long
h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0)
IF h <> INVALID_HANDLE_VALUE THEN
Dim te As THREADENTRY32
te.dwSize = LenB(te)
if Thread32First(h, &te) THEN
DO
IF te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + LenB(te.th32OwnerProcessID)) THEN
MsgBox "Process " & te.th32OwnerProcessID & "Thread " & te.th32ThreadID
END IF
te.dwSize = LenB(te)
LOOP WHILE (Thread32Next(h, &te))
CloseHandle(h)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|