   Getting the threads of a process.
  Hi!I'm trying to get a list of the thread ids of a specific process.I read that I can iterate through the threads using "CreateToolhelp32Snapshot","Thread32First" and "Thread32Next", but then I go through all the running threads in all the running processes.Is there a more efficient way?thanks :)   
  I've not seen a better way to do it than this:Traversing the Thread ListKeep in mind this only applies to Windows, so for other platforms you'll need other platform-specific code.   ;Quote:Original post by ZipsterI've not seen a better way to do it than this:Traversing the Thread ListKeep in mind this only applies to Windows, so for other platforms you'll need other platform-specific code.ok, thanks :)   ;  Hmmm... and one more question:How can I get the handle of the thread once I have its ID?   ;  Try ::OpenThread with the ThreadId ( see OpenThread-Documentation ) for more detailed infos.Kimmi   ;OpenThread.Depending on your usage, the access rights should be something like READ_CONTROL.When you are finished with the handle, be sure to close it by using the CloseHandle function.EDIT: damn, ninja'd by Kimmi due to slow internet connection.   ;  I tried using OpenThread() on a thread in my process but I get a different handlethan the one I get by using GetCurrentThread().I know that the handle by GetCurrentThread() is ok, because SuspendThread() works with it. with the one from OpenThread - it does not.this is how I use it:m_threadHandle = OpenThread(READ_CONTROL, TRUE, tid);tid - is the thread id.why doesn't it work?   ;Quote:Original post by IdovI tried using OpenThread() on a thread in my process but I get a different handlethan the one I get by using GetCurrentThread().I know that the handle by GetCurrentThread() is ok, because SuspendThread() works with it. with the one from OpenThread - it does not.this is how I use it:m_threadHandle = OpenThread(READ_CONTROL, TRUE, tid);tid - is the thread id.why doesn't it work?GetCurrentThread() will give you a different handle from OpenThread(READ_CONTROL) because the two handles have different access restrictions, even though they both refer to the same object.From SuspendThread:Quote:hThread [in]A handle to the thread that is to be suspended.The handle must have the THREAD_SUSPEND_RESUME access right. For more information, see Thread Security and Access Rights.READ_CONTROL doesn't include THREAD_SUSPEND_RESUME, so you can't use it to call SuspendThread().   ;  ok!thanks :)   