Quote Originally Posted by jmcilhinney
Don't call Kill on a Process that has a main window unless it refuses to close of its own accord. Calling Kill is like using the Task Manager to end a process. Would you do that without just clicking the Close button on the title bar first?
VB Code:
  1. 'Ask the process to exit by closing its main window.
  2. If myProcess.CloseMainWindow() Then
  3.     'The call was successful so wait a reasonable period for the process to end normally.
  4.     myProcess.WaitForExit(5000)
  5. End If
  6.  
  7. 'Check whether the process has ended.
  8. If Not myProcess.HasExited Then
  9.     'Force the process to end.
  10.     myProcess.Kill()
  11. End If
Kill is for processes without a main window (not including services, which can be stopped using a ServiceController) or processes that refuse to respond to CloseMainWindow.
so u modify the code to...

VB Code:
  1. Dim handle as integer
  2. For i as integer = 0 to procall.length - 1
  3. If procall(i).mainwindowhandle = handle then
  4. If procall(i).CloseMainWindow() Then
  5.     'The call was successful so wait a reasonable period for the process to end normally.
  6.     procall(i).WaitForExit(5000)
  7. End If
  8.  
  9. 'Check whether the process has ended.
  10. If Not procall(i).HasExited Then
  11.     'Force the process to end.
  12.     procall(i).Kill()
  13. End If
  14. Exit for
  15. Endif
  16. Next