Knowing the process, you need to bring it flows. Who knows how to implement it? With primerchik, if possible, or a link to the source ...
Help, plz.
Knowing the process, you need to bring it flows. Who knows how to implement it? With primerchik, if possible, or a link to the source ...
Help, plz.
There is a WinAPI function CreateToolhelp32Snapshot , which takes a snapshot of processes. You will only have to go through the list of threads and select those that are interesting for the functions Thread32First
and Thread32Next
.
Example:
uses PsAPI, TlHelp32, Windows, SysUtils; //выводит список потоков function GetThreadsInfo(PID:Cardinal): Boolean; var SnapProcHandle: THandle; NextProc : Boolean; ThreadEntry : TThreadEntry32; begin SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); //Создаем снэпшот всех существующих потоков Result := (SnapProcHandle <> INVALID_HANDLE_VALUE); if Result then try ThreadEntry.dwSize := SizeOf(ThreadEntry); NextProc := Thread32First(SnapProcHandle, ThreadEntry);//получаем первый поток while NextProc do begin if ThreadEntry.th32OwnerProcessID = PID then begin //проверка на принадлежность к процессу Writeln('Thread ID ' + inttohex(ThreadEntry.th32ThreadID, 8)); Writeln('base priority ' + inttostr(ThreadEntry.tpBasePri)); Writeln('delta priority ' + inttostr(ThreadEntry.tpBasePri)); Writeln(''); end; NextProc := Thread32Next(SnapProcHandle, ThreadEntry);//получаем следующий поток end; finally CloseHandle(SnapProcHandle);//освобождаем снэпшот end; end;
You can get the PID of your process using the GetCurrentProcessId
function.
UPD1. By simple manipulations with the above code, it is easy to get a function that returns the PID by the process name:
function GetPIDByName(const name: PWideChar): Cardinal; var SnapProcHandle: THandle; ProcEntry : TProcessEntry32; NextProc : Boolean; begin Result := 0; SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); try ProcEntry.dwSize := SizeOf(ProcEntry); NextProc := Process32First(SnapProcHandle, ProcEntry); while NextProc do begin if StrComp(name, ProcEntry.szExeFile) = 0 then Result := ProcEntry.th32ProcessID; NextProc := Process32Next(SnapProcHandle, ProcEntry); end; finally CloseHandle(SnapProcHandle); end; end;
TThreadEntry : TThreadEntry32;
should be ThreadEntry : TThreadEntry32;
, an extra letter Т
in the variable name. - SoftRWriteln
accordingly. - Nofate ♦Source: https://ru.stackoverflow.com/questions/40576/
All Articles