Private Sub KillProcess(byval ProcessName as string)
Dim prc() As Process
Dim ERROR_FILE_NOT_FOUND As Integer = 2
Dim ERROR_ACCESS_DENIED As Integer = 5
Try
prc = System.Diagnostics.Process.GetProcessesByName("ProcessName")
Dim eprc As IEnumerator = prc.GetEnumerator
eprc.Reset()
While eprc.MoveNext
Dim proc As Process = CType(eprc.Current, Process)
proc.Kill()
proc = Nothing
End While
eprc = Nothing
prc = Nothing
Catch e As Win32Exception
If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
MessageBox.Show(e.Message + ". Process not found.")
Else
If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
' Note that if your word processor might generate exceptions
' such as this, which are handled first.
MessageBox.Show(e.Message + ". You do not have permission to kill this process.")
End If
End If
End Try
End Sub