Close all applications

hi Guys I need help in closing all desktop applications. could some one guide me how can i do in. in production enviroment, do we kill or close applications based on user/login. how can i achieve it.

Thanks.

Hi @Rani1978

You can use kill process activity instead of close applicationbjust pass the process name in process within double quotes and check

Thanks
Ashwin.S

@Rani1978

I didnt get it, do you have a sample. It would be great if you can share. Many Thanks.
Also what if i have 4 desktop applications to close. I would use GetProcesses, loop at it, now I want to loop through the list of desktop applications that i want to kill. how can i achieve this.
Thanks again.

@Rani1978
Do you want to close all running process or just a specific process?

@Rani1978
Sequence1.xaml (5.4 KB)
This get then loop all the open process and find the notepad then close it. Just remove the if statement if you want to close all the processes.

Hi @Rani1978

Please try the attached workflow. It will kill all the foreground processes except UiPath.Executor and UiPath.Studio

Hope this will help Main.xaml (5.1 KB)

Thanks
Anoop

Hi when i open the file i see only missing activity. How can i rectify this. or is it possible to send the screen shot of the workflow.
Many thanks again.

image

Hi Anoop, I was able to open the xaml file. Thanks for the help.

Hi Anoop,
I have another doubt, When i am doing close application. do i put it in Try-Catch , if yes what should be in Catch, do we have kill process. In catch what should be the exception, should it be system or business exception.

Hi @Rani1978

You can use system exception depending on the further action you are taking. If it fails at the kill activity then you can retry the same.

Hi guys, can I ask for the link on where to ask questions? I am sorry I’m new to UiPath

@Mannix_Tapawan Click on New Topic and type your questions

Best Regards,
Vrushali

1 Like

This can easily be done with the invoke powershell activity, make sure you select the option for the item as is script and enter the below:

#Closing all window shell windows like Windows Explorer#
$shell = New-Object -ComObject Shell.Application
foreach ($window in $shell.windows())
{$window.quit()}

#Killing all processes with open windows except for UiPath labeled processes#
Get-Process | Where-Object {$.MainWindowTitle -ne ‘’} | Where-Object {$.ProcessName -notmatch ‘UiPath’} |stop-process -Force

For some reason this online forum is removing the required “$” and “_” from the previously posted script

underscore = _

_.MainWindowTitle should be $underscore.MainWindowTitle
and
_.ProcessName should be $underscore.ProcessName