I am trying to kill a process by using the following code

Dim aprocess As System.Diagnostics.Process
        aprocess = System.Diagnostics.Process.GetProcessesByName("E:\\preview.mp3")
        aprocess.Kill()

however i am getting an error


Value of type '1-dimensional array of System.Diagnostics.Process' cannot be converted to 'System.Diagnostics.Process'.

you need to loop through the found processes.

Dim aprocess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("E:\\preview.mp3")
for each proc as System.Diagnostics.Process in aprocess
        proc.Kill()
next

you need to loop through the found processes.

Dim aprocess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("E:\\preview.mp3")
for each proc as System.Diagnostics.Process in aprocess
        proc.Kill()
next

Not working.....

Actually i have made two subs
in first sub

System.Diagnostics.Process.Start("E:\\preview.mp3")

and in another sub i copy pasted the above code

Dim aprocess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("E:\\preview.mp3")
        For Each proc As System.Diagnostics.Process In aprocess
            proc.Kill()
        Next

when the first sub is called the mp3 file runs but it does not exit in second sub.....

Thank you i Got it..it worked
Since I am this mp3 file I am trying to run is being used by VLC media player
Instead of killing the mp3 file I have to kill the vlc
So your code Becomes

Dim aprocess() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("vlc")
        For Each proc As System.Diagnostics.Process In aprocess
            proc.Kill()
        Next

Thank you anyways You helped a lot

This question has already been answered. Start a new discussion instead.