Well, my stupid. It was the name of a function that was misplaced below my main procedure. Thus not found. I thought that it was some kind of parameter like SysUtils.ExecuteProcess(...).
Not all was lost because it caused me to dig and find another way using taskkill.
//Terminate process by processID
function TerminateProcessByID(ProcessID: Cardinal): Boolean;
var hProcess : THandle;
begin
Result := False;
hProcess := OpenProcess(PROCESS_TERMINATE, True, ProcessID);
if hProcess > 0 then
try
Result := Win32Check(Windows.TerminateProcess(hProcess,0));
finally
CloseHandle(hProcess);
end;
end;
//Get running processes list and kill a process if running
procedure TForm1.TerminateProcess(ProcessName : string);
var Snapshot: THandle; pe: TProcessEntry32;
begin
Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
try
pe.dwSize := SizeOf(pe);
if Process32First(Snapshot, pe) then
while Process32Next(Snapshot, pe) do begin
if uppercase(ProcessName) = uppercase(pe.szExeFile) then begin
TerminateProcessByID(pe.th32ProcessID);
end;
end;
finally
CloseHandle(Snapshot);
end;
end;
procedure TForm1.ProcessRtn(ProcessLine, Param: string);
var AProcess: TProcess;
begin
AProcess := TProcess.Create(nil);
try
AProcess.ShowWindow := swoHIDE;
AProcess.CommandLine := ProcessLine + ' ' + Param; //'Taskkill /F /PID 4612';
AProcess.Execute();
Application.ProcessMessages;
sleep(3000);
finally
AProcess.Free();
end;
//tasklist > tasklist.txt
//ProcessRtn('taskkill', ' /F /PID 5288');
end;
I know that AProcess.CommandLine is depreciated, but it shouldn't be in my opinion. It is the only way to successfully to kill a process.