Darryl Smith @ Radioactive Networks: Killing a process in VB.NET

Thursday, October 28, 2004

Killing a process in VB.NET

I spent some time today searching form information on how to kill a process using VB.NET. I was surprised that this was harder than I thought it would be. Mainly because the information does not seem to be documented very well.

Eventually I found some minor links which suggested some help words for searching in the VB.NET help file. There is a data type called PROCESS which can hold information about processes. In a networked environment you can play with processes on other computers. Since I am dealing with a local machine, things are easier.

The code works by getting all the processes on the local machine into an array, and then checking each of them to see if the process name is what we want. If it is we KILL the process.

Normally you would not use KILL since it does not shut things down properly. In my case I do not care since I know that there is an issue because I have already attempted to kill off the process by stopping the service.

So here is the code.

Dim local As Process() = Process.GetProcesses
Dim i As Integer
For i = 0 To local.Length - 1
Debug.WriteLine(local(i).ProcessName)
If Strings.UCase(local(i).ProcessName) = Strings.UCase("ProcessName") Then
local(i).Kill()
TextBox1.Text = "Found process and Killed Process"
End If
Next

1 Comments:

Blogger shalu said...

Hi

The code 'Killing a process in VB.net' is tooooo good, simple, easy to understand.

It was really v.helpfull for me.

Salini.

9:03 PM  

Post a Comment

<< Home