function GetPIDByProgramName(const APName: string): DWORD;
var
isFound: boolean;
AHandle:THandle;
ProcessEntry32: TProcessEntry32;
begin
try
Result := 0;
AHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry32.dwSize := Sizeof(ProcessEntry32);
isFound := Process32First(AHandle, ProcessEntry32);
while isFound do
begin
if (UpperCase(StrPas(ProcessEntry32.szExeFile)) = UpperCase(APName)) then
begin
Result := ProcessEntry32.th32ProcessID;
break;
end;
isFound := Process32Next(AHandle, ProcessEntry32);
end;
finally
CloseHandle(AHandle);
end;
end;