Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Feb : Why can't I terminate a process?

www.cryer.info
Managed Newsgroup Archive

Why can't I terminate a process?

Subject:Why can't I terminate a process?
Posted by:"Ace" (askaquesti..@rogers.com)
Date:Sat, 19 Feb 2005 22:50:33

Why is it when I try to terminate any process as follows, I get error number
6? What am I doing wrong? I want to terminate the process without user
presence required, so please don't suggest the postmessage function. You may
notice that I'm putting this code into FormCreate. Yes, that's what I want,
because that's the only thing I want this program to do.

procedure TForm1.FormCreate(Sender: TObject);
var h: HWND;
begin
  h := FindWindow(nil, 'Project1');
  if h <> 0 then
  begin
    terminateprocess(h, 0);
    showmessage('Faulted with error: '+inttostr(getlasterror()));
  end
  else showmessage('did not even try');
end;

Replies:

www.cryer.info
Managed Newsgroup Archive