Hi!!
I'm trying to make a small application that can terminate a proces. First I want to get the pid of a file that has a window title "test". Then the program should terminate the process by pid.
I tryed this:
procedure TForm1.Button1Click(Sender: TObject);
var h, pid, ph : cardinal;
begin
h := FindWindow('test', nil);
GetWindowThreadProcessID(h, @pid);
ph := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
Process(ph).Terminate;
end;
What is going wrong?
Trying to terminate process
FindWindow's first parameter is the class name, not the title text. Btw, if you use madKernel, you can simply do this:
However, if terminating a process is all you need to do, you can also easily do it without madKernel. In that case just replace "Process(ph).Terminate" with "TerminateProcess(ph, 0)" and swap the FindWindow parameters.
Code: Select all
Window('*', 'test').OwnerProcess.Terminate;