How to kill a process for current user with one line power shell code

SCENARIO

KILL PROCESS - plays a major role in all the enterprise level workflows especially with the process built using REFramework template, where we have a separate workflow either to kill all the open application.

It’s well known for everyone that a simple kill process will close all the application by mentioning those application exe file name in PROCESSNAME property.

But what if your bot is running in a concurrent runtime machine where multiple user will be running bot at the same, May be they might be using the same application that you are trying to kill.

In order to avoid such scenario we need to kill it for specific user ensuring that application is not killed with other users.

SOLUTION

Have a view on this workflow and just invoke in your framework

Kill Powershell.zip (5.0 KB)

OTHER APPROACHES

If we want to do by getting all the process names and kill them

  1. Get the current user name by Environment.UserName. Store it in a variable
  2. Get the List of all Processes running under current user
  3. Use a " ForEach " activity and loop through all process names
  4. Use an “If” activity inside the loop and check if the below condition is met or not for the “If” activity
  5. processName=“ YourProcessName ” AND UserName= Environment.UserName
  6. If the condition is met then use " Kill Process " activity inside the “Then” block of “If” activity to kill the process

NOTE
If you are using from 21.4 System Activity pack or 21.4-beta which is already available in the official feed, we can choose the current user option with the KILL PROCESS activity itself

There is a property called AppliesTo

  • AppliesTo - Kill process only if it belongs to the current user or session. Select one of three options: All , OnlyCurrentUser , OnlyCurrentSession . The default value is none.

Happy automation :robot:

Cheers

4 Likes