Trying to terminate process

delphi package - easy access to kernel objects etc.
Post Reply
shamers
Posts: 7
Joined: Wed Jun 07, 2006 6:46 pm

Trying to terminate process

Post by shamers »

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?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

FindWindow's first parameter is the class name, not the title text. Btw, if you use madKernel, you can simply do this:

Code: Select all

Window('*', 'test').OwnerProcess.Terminate;
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.
Post Reply