Kill process under Windows NT

 

Comment from Epsylon  07/10/2001 07:53AM PST 

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; 

Comment from Jaymol  07/10/2001 08:43AM PST 

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. 

Comment from BlackDeath  07/10/2001 09:11AM PST 

;-)

 

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. 

Comment from SChatel  07/10/2001 09:12AM PST 

Jaymol,

It works but only if I close my Delphi application 

Comment from BlackDeath  07/10/2001 09:12AM PST 

eh - for use in delphi use API-function ShellExecute or ShellExecuteEx, as you like. 

Comment from BlackDeath  07/10/2001 09:21AM PST 

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. 

Accepted Answer from ziolko  07/10/2001 11:06PM PST 

Check out my previouse Q:

/jsp/qManageQuestion.jsp?ta=delphi&qid=10372556

You can kill anything not only excel :-)))

ziolko/