I am designing an automation where I need to interact with 5 different application. At the end of it, I will close all applications in the “End Process” workflow of REFramework.
Instead of directly using “Close Application” activity, I want to first check if process for it is running or not. Will use the close activity only if process is running.
With “Get process” activity , I am able to extract all the running processes. But how to find if the process I am looking for is in the list??
Check the name of processes in Windows task manager when they are running.
Once you get the names, use a for each loop to iterate over all the processes you got from get process, then check if item.contains that process you can close it in the then flow or leave blank in else.
we can do it with: Process.GetProcessesByName(…
BUT we should keep in mind:
only processes for our bot are relevant. We dont want touch other running session’s processes
processes can also have sub processes
also have a look here:
with myPID = Process.GetCurrentProcess.SessionID
you will get a marker of current user
getting the processes by name
currentProcessByName = Process.GetProcessByName(YourProcessName)
filtering to current user:
UserProcess = currentProcessByName.Where(Function (x) x.SessionId=myPID ).toArray
for a defensive kill have a look here and just combine both approaches: