0
votes

I've recently started learning VB.NET and I'm wondering is there an easy way of killing off all processes a VB.NET application uses, for example I've created a form which pings a given IP address, this application creates a process cmd.exe and sends the ping argument, this in turn creates following processes:

  • cmd.exe
  • conhost.exe
  • ping.exe

If I Kill () the main process it kills off cmd.exe but not conhost.exe nor ping.exe, do I need to manually kill these also? By killing off the main process will it not automatically kill off associated processes? If that makes sense. Another thing I don't understand, I tried using Close () but nothing appears to happen, all processes keep on running. I want to be able for a user to close the form and for all associate processes to be closed/killed.

1
sounds fishy to me like a Trojan activity here.... but generally speaking child processes are killed as long as... they ARE child processes and you look at the right parent process. if nothing "happens" then maybe there is nothing for it to happen. did you read the documentation? perhaps the processes are spun up in a different manner than you would think.... - Ahmed ilyas
This is how you get from bad to worse. Don't use ping.exe, use the System.Net.NetworkInformation.Ping class. - Hans Passant

1 Answers

1
votes

It is much better to use the System.Net.NetworkInformation.Ping class to perform a ping (as Hans Passant mentioned).

In general, if you use proc = System.Diagnostics.Process.Start(...), you should be able to kill the process and its child processes with proc.kill. However, it is possible for a process to launch other processes that will not be immediately terminated with kill. It would be a bad idea to terminate leftover processes manually, for a number of reasons.