UiPath - Kill Process for Current User

uipath kill process for current user
UiPath - Kill Process for Current user

Kill Process activity in UiPath terminates a specified process from the machine/server.

This activity kill process for every user session, and this would create problem for other users working on the server. This would also create problem to work with High Density Robots features of UiPath.

In order to avoid these issues and for good practice in development, we should kill process for current user only on machine/server.

Below is the uipath code to kill process for current user.

Step 1 – Take a variable/argument (string array) contains the process names needed to be killed.

in_ProcessArrayToKill = New String(){"excel", "iexplore"}

kill-process-for-current-user-uipath
Initialize String Array with Process names to be killed

Step 2 – Get All Processes

processList = Process.GetProcesses

kill-process-current-user
Get All Processes

Step 3 – Get Current session Username

currentUsername = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(System.Environment.UserDomainName+"\","")

uipath-kill-process-for-current-user
Get Current Session Username

Step 4 – Perform "For Each" loop over all processes

Use "For Each" loop over variable "processList" and take the "TypeArgument" as "System.Diagnostics.Process"

Step 5 – Inside "For Each" loop, get username of the current process inside loop

itemProcessUsername = itemProcess.StartInfo.Environment("Username")

uipath-kill-process
Get Process Username

Step 6 – Inside "For Each" loop, check condition using "If activity" whether the current process is under "processList" to be killed and current process username is of current session username

uipath-kill-process-excel
Check Process for Current User

Step 7 – Inside "For Each Loop", If the above condition meets then kill the process

uipath-kill-process-for-current-user
Kill Process Properties

Comments

Popular posts from this blog

UiPath - Convert String to DateTime

Filter DataTable in UiPath Studio