Yo utilizo este código para cerrar una aplicación con el administrador de tareas de Windows. Puedes modificarlo para verificar si el exe ya esta abierto.
Código Delphi
[-]
procedure TerminateProcessByName(const ProcessName: string);var
ProcessID: DWORD;
hProcess: THandle;
ExitCode: DWORD;
begin
ProcessID := GetProcessIDByName(ProcessName);
if ProcessID <> 0 then
begin
end;
end;
function GetProcessIDByName(const ProcessName: string): DWORD;
var
SnapshotHandle: THandle;
ProcessEntry32: TProcessEntry32;
begin
Result := 0;
SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if SnapshotHandle <> INVALID_HANDLE_VALUE then
begin
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
if Process32First(SnapshotHandle, ProcessEntry32) then
begin
while Process32Next(SnapshotHandle, ProcessEntry32) do
begin
if SameText(ExtractFileName(ProcessEntry32.szExeFile), ProcessName) then
begin
Result := ProcessEntry32.th32ProcessID;
Break;
end;
end;
end;
CloseHandle(SnapshotHandle);
end;
end;
Lo probe en Windows 10 y 11 y funciona perfecto
