Kill a process only if it's running, without looping through every running process

Hi there @HsDev,
You can use the following:

strProcessName = "javaw"
If System.Diagnostics.Process.GetProcesses.AsEnumerable().Any(Function (prcRunning) prcRunning.ProcessName.ToLower.Trim.Equals(strProcessName.ToLower.Trim)) Then

  • Kill Process - ProcessName = strProcessName.ToLower.Trim

End If

10 Likes