Link to home
Start Free TrialLog in
Avatar of Manuel Lopez-Michelone
Manuel Lopez-MicheloneFlag for Mexico

asked on

Killing a process...

Hi guys,

I want to kill a running process... I am using delphi 7 and windows xp sp2... How I can do that?

regards
Lopem
Avatar of 2266180
2266180
Flag of United States of America image

you will use TerminateProcess(<PID>,<exit code>); if you don't know the PID, you can find it by listing all processes and finding the right one by name: http://delphi.about.com/od/windowsshellapi/l/aa080304a.htm
Avatar of Manuel Lopez-Michelone

ASKER

any code to share, please?
regards
Lopem
well the code is already there on delphi.about.com. you didn't give any specific information so I cannot make a code that will work for anything. if you have the pid of the process then you call terminateprocess on that pid and you're done. if you don't have the pid, then you must search somehow for that application. there are more ways of doing depending on what information you have about that process (executabl path, window title, etc. all are done differently). I gave you a solution for searching through names. if that is nbot the information you hold., then you must tell us what you do know about the process you want to kill.
Hi again, Ciuly, thanks for your rapid answer. I need to kill msn messenger only if it is loaded... I know if the msn messenger is active using:

function ActiveCaption: string;
var
  Len: LongInt;
  Title: string;
  Handle : THandle;
begin
  Result := '';
  Handle := GetForegroundWindow;
  if Handle <> 0 then
  begin
    Len := GetWindowTextLength(Handle) + 1;
    SetLength(Title, Len);
    GetWindowText(Handle, PChar(Title), Len);
    ActiveCaption := TrimRight(Title);
  end;
end;

and calling this function this way:

  Label1.Caption := ActiveCaption;
   if Pos('MSN Messenger', Label1.Caption)<> 0 then
   begin
     //I want here to put the code to kill the msn messenger...
   end;

regards
Manuel Lopez (lopem)
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
let me try! thanks man.
regards
Lopem