Making Excel really quit in a vb dot net application

A

Al Christoph

I have a console application in vb 2003. The essence of it is

dim xla as microsoft.office.interop.excell.application
function main(arg() as string) as integer
try
xla = new microsoft.office.interop.excell.application
' make a living doing this
catch ex as exception
' exception processing goes here
finally
xla.quit
xla = nothing ' can't hurt:)
end try
console.readline()
return 0
end

All is happy except for one thing. If i use the X on the console window to
terminate the application (a no - no I know), Excel continues to run. If I
quit by doing the readln() then Excel shuts down.

Why is this so????

What can I do to further goose Excel so that it ir really dead and buried by
the time the program gets to the readline?

Regards,
Al
 
J

John.Greenan

There's only one way do absolutely kill excel and that's using the windows
API to find any process with a name like excel, get the pid and then kill it.

You CANNOT rely on application.quit. It will inevitably leave zombie excel
instances hanging around in memory. And you cannot look for the application
by using getobject and then quitting - the zombies will ignore you.

MS justify this by the bland statement that Excel is not a server
application. The firm I work for writes a commercial application that runs
Excel on the server side, so we spent a lot of effort on being able to
definitely kill excel.

Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctgetobject.asp

for some tips as well

Note: Apologies to unix types who give a specific meaning to zombie, I mean
something similar, but not identical
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top