uses TlHelp32,PsAPI
function Execheck(exename:string): string;
var
aSnapshotHandle: THandle;
ContinueLoop: BOOL;
aProcessEntry32: TProcessEntry32;
handle : thandle;
begin
aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
aProcessEntry32.dwSize := Sizeof(aProcessEntry32);
result := '';
ContinueLoop := Process32First(aSnapshotHandle, aProcessEntry32);
handle := 0;
while integer(ContinueLoop) <> 0 do
begin
if (Exename = aProcessEntry32.szExeFile) then
begin
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, aProcessEntry32.th32ProcessID);
if
Handle <> 0 then
begin
SetLength(Result, MAX_PATH);
if GetModuleFileNameEx(
Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
CloseHandle(
Handle);
end;
end;
ContinueLoop := Process32Next(aSnapshotHandle, aProcessEntry32);
end;
CloseHandle(aSnapshotHandle);
end;