pasmonytar seems tray util. thats not what i need. this code.
program ProcessFindPID;
{$mode objfpc}{$H+}
uses
Classes, Sysutils, Windows, JwaTlHelp32;
function QueryFullProcessImageName(hProcess: HANDLE; dwFlags: DWORD; var lpExeName: LPTSTR;
var lpdwSize: LPDWORD): BOOL; stdcall; external 'KERNEL32.dll';
function FindInProcesses(const PName: string): DWord;
// Looks for process with PName executable and return
var
i: integer;
CPID: DWORD;
CProcName: array[0..259] of char;
S: HANDLE;
PE: TProcessEntry32;
begin
Result := 0;
CProcName := '';
S := CreateToolHelp32Snapshot(TH32CS_SNAPALL, 0); // Create snapshot
PE.DWSize := SizeOf(PE); // Set size before use
I := 1;
if Process32First(S, PE) then
repeat
CProcName := PE.szExeFile;
CPID := PE.th32ProcessID;
//if CProcName = '' then Writeln(IntToStr(i) + ' - (' + IntToStr(CPID) + ') Failed to get a process name')
Inc(i);
if UpperCase(CProcName) = UpperCase(PName) then
{ Found the name. Set Result to the PID of process found }
Result := CPID;
until not Process32Next(S, PE);
CloseHandle(S);
end;
begin
writeln('Explorer.exe has process id '+inttostr(FindInProcesses('explorer.exe')));
end.
Works fine to get the pid. im sure there more options possible.
As example i have the pid but need to know if the process is still running.
ANd with JwaTlHelp32 i think you can also read cpu info and memory useage of the process by pid. Only finding the manual... google not really helpfull.
Tried some delphi code "processinfo" but that seems not really compatible with lazarus and thrping errors.
Most important what i need is the option to check if pid is still running.
memory useage and cpu would be nice.