Skip to content
Advertisement

How to close all child processes in C#

C# code:

JavaScript

I am calling a java.exe from C# windows application. java.exe is used to test some websites. Java using Selenium to test the webpages by opening default web browser. It will open 3 to 10 times browsers and test the test cases. I want to add stop button in C# application and when we click it then it should close java.exe as well as those opened browsers. How to do it?

I tried to get process names by using exe name like this

JavaScript

But it is not working.

Advertisement

Answer

JavaScript

Before starting a new process I have stored the processId in a global variable.

JavaScript

I called KillProcessAndChildren(javaExeProcessId); to kill the current process and its child processes wherever required.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement