function findProcess(exeName:string):integer; var pe:TProcessEntry32; th:integer; begin th:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); LogWrite(-1, ' Find process with name "'+exeName+'" [enum handle='+inttostr(th)+']'); exeName:=AnsiUpperCase(exeName); Result:=-1; try Process32First(th, pe); repeat try if AnsiUpperCase(ExtractFileName(pe.szExeFile))=exeName then begin result:=pe.th32ProcessID; Exit; end; finally if pe.th32ProcessID>0 then begin if Result<0 then LogWrite(-1, ' process "'+pe.szExeFile+'" with id='+inttostr(pe.th32ProcessID)+', no, look next') else LogWrite(-1, ' process "'+exeName+'", MATCH!'); end; end; until not Process32Next(th, pe); finally CloseHandle(th); end; end;