How to use Kill Process

I am trying to close application after finishing the process.However am not clear of what values to populate in the Target Section for Process and Process Name.Can anyone give me a sample example please?

1 Like

This works for me:

6 Likes

Sorry i dint quite understand this solution.Could you please elaborate? .

You have to pass either Process or ProcessName.

For Instance if you have to Close outlook

  1. Use GetProcesses (collection) and loop it untill you get your Proccesses and kill them (multiple) using Kill Process

  1. Kill one process use Kill Process Activity and pass one of below
    process = System.Diagnostics.Process.GetProcessesByName(“OUTLOOK”) —> process
    “OUTLOOK” —> processname
18 Likes

Kusum,

What I do to kill multiple applications is to call a bat file to close all of them at the same time. The bat file contains a list of taskkill commands as follows

taskkill /f /t /im iexplore.exe
taskkill /f /im excel.exe

I find this usefull as it avoids having to handle error messages like, ‘do you want to close all tabs’ in IE

Hope this helps

6 Likes

Thanks that helped!

Hi vvaidya,

First of all, thanks for providing the example!

I’m trying to use this “Kill process” to terminate “Chrome” browser processes.

So for those 2 criteria: Process and ProcessName, I can’t quite figure out how to deal with them.

What I’ve tried is, in “Process”, I wrote:
program = system.Diagnostics.Process.GetProcessesByName(“chrome”)

But I got the error:
image

Could you help elaborate what did I do wrong?

And also, I don’t quite understand the point of using “ProcessName”.

Here are some samples of the processes (I did a loop on them and used process.tostring sort of thing to see the results)
System.Diagnostics.Process (svchost)
System.Diagnostics.Process (svchost)
System.Diagnostics.Process (igfxext)
System.Diagnostics.Process (smss)
System.Diagnostics.Process (chrome)
System.Diagnostics.Process (svchost)
System.Diagnostics.Process (svchost)
System.Diagnostics.Process (WmiPrvSE)
System.Diagnostics.Process (taskhostw)
System.Diagnostics.Process (explorer)
System.Diagnostics.Process (svchost)
System.Diagnostics.Process (iPodService)
System.Diagnostics.Process (cmd)

Does it mean the “svchost”, “explorer” are “ProcessName”?
I did try putting “chrome” in the ProcessName field, but it doesn’t work.

Thanks a lot for the help!

BR
Hao

1 Like

Hi @hellitonwoo

Process is the process type object to be selected to kill. As you can see in the error message, it is recommended to use “Is” instead of “=”, but this would retrieve a boolean value that would not be compatible to the System.Diagnostics.Process type.
So you could just write System.Diagnostics.Process.GetProcessesByName(“chrome”)(0) – it will kill the first chrome process in the AllProcesses list.
Or a much simple solution would be to give directly the ProcessName as string: just type “chrome”.

Yes, those are the Process names.

5 Likes

I guess you have to keep if condition in for each

If Program.ProgramName =“chrome”

In kill activity just pass Program

1 Like

Sorry Process.ProcessName

Hi vvaidya,

I’m using If else activity inside for each activity. If my else block executed means. i don’t want to iterate for each loop again.But i want to skip the for each loop. So, could you help me to come to come out of this.

Don’t make it complicated. Just use process names you are using in process.
Example: Suppose you are using EXCEL and OUTLOOK, please use the code given below.

To kill Excel drag Kill Process Activity and pass Process name property as EXCEL

To kill Outlook drag Kill Process Activity and pass Process name property as Outlook

Please find attached snapKillOutlook

14 Likes

@pravin.patil, your recipe works and kills targeted processes. But it always ends with Aggregate Exception. Why is it so? Do you know how to avoid that?

Can you share the activity screenshot with the property panel.

Hi,
Try putting “true” in ContinueOnError option.

2 Likes