0

I currently have the following up in VS 2010

        Dim myProcess() As Process = System.Diagnostics.Process.GetProcessesByName("calc")

    For Each myKill As Process In myProcess
        myKill.Kill()

However I cannot seem to get it to kill more than one process. Example I've tried

("calc",mspaint")
("calc,mspaint")
("calc"),("mspaint")

Any ideas? Thanks for your time/support

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Harold Giddings
  • 93
  • 1
  • 11

1 Answers1

2

Quote from MSDN documentation of GetProcessByName:

Creates an array of new Process components and associates them with the existing process resources that all share the specified process name.

You can't pass an array of arguments to it.Instead,you can get all the processes using the GetProcesses method,iterate over all processes and check if its name match one of the names you want:

 Dim procs = System.Diagnostics.Process.GetProcesses().Where((Function(p) p.ProcessName = "calc" Or p.ProcessName = "mspaint"))
            For Each p As Process In procs
                p.Kill()
            Next

Non-LINQ way:

 For Each p As Process In Process.GetProcesses()
            If p.ProcessName = "calc" Or p.ProcessName = "mspaint" Then
                p.Kill()
            End If
        Next
Ceramic Pot
  • 280
  • 2
  • 14
  • Thanks :) That works. But what I wanted to kill any more than two? (i'll work on it myself in the mean-time) – Harold Giddings Apr 11 '12 at 02:26
  • NVM last comment, I did this For Each p As Process In Process.GetProcesses() If p.ProcessName = "calc" Or p.ProcessName = "mspaint" Or p.ProcessName = "pidgin" Then p.Kill() End If Next – Harold Giddings Apr 11 '12 at 02:27