Kill process started with System.Diagnostic.Process.Start("FileName")

Process.Start(string,string) returns you a Process resource that you can use to further control the new process.

Process newProcess = Process.Start("param1", "param2");
if (newProcess != null && !newProcess.HasExited)
  newProcess.Kill();

The same structure works if you use Process.Start(string), or any other static Process.Start overload.

Process.Start() is a member function and associates a new or reused Process with the Process component identified by this. Behaviour of this method depends on the properties of the Process identified by this.


Don't do it this way.

It's not clear whether the intent of your program is 'Always launch with Windows Media Player' or 'Launch with the registered MP3 player', which might be, say, iTunes.

If you need WMP, use Process.Start with the full path to windows media player.

If you need the registed MP3 player, you can find out the correct exe using the code shown here. Again, start the process with this exe path, passing the MP3 as a parameter.


Two ways:

1-

Process customProc = Process.Start("ExecutablePath", "Argument(s)");  
customProc.Kill()

2-

Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("ProcessName")  
For Each p As Process In pProcess
p.Kill()
Next

Tags:

C#

.Net

Vb.Net