Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to kill Outlook.exe 1

Status
Not open for further replies.

MikeDamone

Programmer
Oct 21, 2003
106
US
I am using the the Outlook Assembly to send meeting requests and I have noticed that outlook.exe stays running as a process in task manager even after my program completes. At the bottom of my code I am logging off the namespace and quitting the application object like so

ons.logoff
oapp.quit

But the process is still running. Anyone know how to kill it? Thanks

 
Code:
For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses

    If p.ProcessName.ToLower = "outlook" Then

        p.Kill()

    End If

Next
You should only use
Code:
Process.Kill()
when you have to - it causes the process to stop executing abruptly and can lead to data loss.

Ordinarily, you should use
Code:
Process.CloseMainWindow()
but in your case the Outlook process has no user interface and therefore the process would not close.
 
in order to use the above code do i need to add anything special to my project or my module???

thanks
mrmovie
 
No, the code sample has fully qualified the Diagnostics namespace.
 
Um, won't this be a problem if the user was actually running an instance of Outlook to begin with?

You could try extending the idea and retrieving the process id of the Outlook your app started, or you could check to see if there is a window associated with the process you are about to kill.

I don't know - I'm just suggesting.

I have, however, seen this problem before with Excel. I think I used gc.collect, and gc.WaitForPendingFinalizers to solve it. Have a look at the post on gotdotnet and try JohnStewein's destruction sequence suggestion.

Mark

Mark [openup]
 
Yeah Custom24, you are right that this could close the wrong instance of Outlook if more than one where open. ActiveSync, for example, will start a hidden instance of Outlook in order to synchronise.

The sample code is an example - there's no exception handler shown either, something I would always include in production code. I guess that I assume (rightly or wrongly) that other programmers are sensible enough to consider exceptions and other issues such as multiple instances.

 
Thanks guys.

Can any of you suggest anything for this problem I have with cancelling a meeting request?

thread796-762424
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top