Wednesday, December 14, 2005

Kill a process in VB.NET

I have had problems with processes that are not closed correctly. This is what I've done after trying to close it the correct way to ensure it is killed. In this case it is Acrobat that I have run.
res = AcroExchAVDoc.Close(False)
Dim myProcesses As Process() = Process.GetProcessesByName("acrobat")
Dim myProcess As Process
For Each myProcess In myProcesses
If myProcess.MainWindowTitle = "" Then myProcess.Kill()
Next myProcess

PS. I have not tried this yet but it could be worth trying to use Marshal.FinalReleaseComObject(AcroExchAVDoc)

2 comments: