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'.

Recommended Answers

All 5 Replies

GetProcessesByName

should give you the idea that you get an array of processes.

What does it mean..am I wrong in approach???

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.