Link to home
Start Free TrialLog in
Avatar of SChatel
SChatel

asked on

Kill process under Windows NT

How can I kill the Windows process "excel.exe" in Delphi ?
Avatar of Epsylon
Epsylon

uses ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  Excel: Variant;
begin
  try
    Excel := GetActiveOleObject('Excel.Application');
  except
    Excel := CreateOleObject('Excel.Application');
  end;
  Excel.DisplayAlerts := False;
  Excel.Quit;
  Excel := Unassigned;
end;
This will close Excel nicely, asking the user if they wish to save any changes (if it's relevant.)

  SendMessage(FindWindow('XLMAIN', nil), WM_CLOSE, 0, 0);

Hope this helps,

John.
;-)

go to dos prompt and just say:

kill -f excel.exe

and all instances of excel will be killed, file open or not, regardlessly of any losses...

nice tool, that kill...

bye,

BlackDeath.
Avatar of SChatel

ASKER

Jaymol,
It works but only if I close my Delphi application
eh - for use in delphi use API-function ShellExecute or ShellExecuteEx, as you like.
and if you want excel to ask you, if the changes should be saved - well, then use

kill excel.exe

with out -f (stands for "force")

kill.exe ist part of the resource kit for windows you can download.

BD.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland 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