0

Hello once again and I need some help. I am developing an automatic updating component to update one of my other apps in vb.net. The problem is that IFF an update is available, the update app has to be able to "kill" the app that is being updated. Note that the update app and program app are 2 separate projects and have no connection what so ever. I am wondering if there is a way to kill that program app's process from the update app. I have looked at several examples, but they start and stop the process in the code. I want to be able to search for a process by name and then kill it(NOT START AS IT IS ALREADY RUNNING). Any help is appreciated! (NOTE: Those who redirect to another link will not get best answer)

Josh Menzel
  • 2,300
  • 4
  • 22
  • 31
  • What I want to accomplish is similar to going into task manager and going to processes and selecting a process to end. – Josh Menzel Nov 25 '12 at 19:56

2 Answers2

1

I have done something similar to this before. If I am understanding your requirements correctly then you need to use the GetProcess in the System.Diagnostic namespace. There is more information about it here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx.

w0051977
  • 15,099
  • 32
  • 152
  • 329
  • yes I know that much, but I need to know how the entire thing works. I want to be able to say: kill this process using a name – Josh Menzel Nov 25 '12 at 20:27
  • Does this link help?: http://stackoverflow.com/questions/116090/how-do-i-kill-a-process-using-vb-net-or-c. I know it is written in C# but it should be simple to convert to VB.NET. – w0051977 Nov 25 '12 at 20:29
  • No problem. If this has answered the question then please mark it as answered. If it has not completely answered the question then please supply more details and I will try to help further. – w0051977 Nov 25 '12 at 21:08
0

Here you can use this function and pass the process name as a parameter.

  Public Function killProcess(ByVal procName As String) As Boolean
    Try
        Dim proc = Process.GetProcessesByName(procName)
        For i As Integer = 0 To proc.Count - 1
            proc(i).Kill()
        Next i

        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

This function takes the process name such as "chrome" and checks for multiple instances and kills each of them.

You can call this function as bellow

killProcess("Process Name")