how do i kill an exe spawned by a batch file?

Hi, I have a batch file which runs a robocopy command. I am using Windows task scheduler to run the scrpt nightly. I have schueduled the batch file to run between 8pm and 8am when the users aren't around so that most files robocopy tries to copy are not in use.

The problem I am having is that if task scheduler terminates the batch file at 8am the robocopy process is still left running. Is there a way I can add to the batch file so that when the batch file closes the robocopy process it has spawned is also terminated?

My batch file is below:



In Windows Scheduler, just run the following as the command to run, not a batch file.



No, you do not have any way to force-close if the batch file is killed. In a batch you also don't know the PIDs of "child" processes. But you can use a particular user for the task, and kill all processes of that user at 8:00am.



In Windows Scheduler, just run the following as the command to run, not a batch file.



Your solution seems to work well, I had a slight issue because I had to map the drives first before the robocopy command, but I solved that by adding an action to map the drives before running the robocopy command. I tested running multiple robocopy jobs on the same computer and only the robocopy process spawned by the schedule task is killed when I terminate the task.

Thanks very much!



Welcome, glad that helped...

~bp



Share this

Related Posts

There was an error in this gadget