1

I have a problem which I think might be solvable with a batch file, but I've only used batch files once or twice and don't know enough to try and solve this on my own. For context I'm running Windows 10 Home Edition, and have some programming experience, though it is primarily mathematical, i.e. R and MATLAB.

The problem is this: I have two programs, in this case Spotify and Toastify, which run together, with Toastify running in the background. I'll refer to them as S and T, respectively. If I run T, S runs as well, but if I close S, T remains running in the background. For reasons of convenience, I would rather that closing S also close T, so that when I want to use them again later I need only reopen T rather than checking if it's still running in the background, because T doesn't let you run multiple instances.

I'm wondering if there is an easy way to write a batch file (or something else if this isn't a good approach) that will open T (and so also S), and then 'listen' for S to close, at which point it closes T as well.

DMcMor
  • 173
  • 1
  • 10
  • Yes there is. You can monitor one process waiting for it to be terminated and after that happened break out of a loop and taskkill the other one. – geisterfurz007 Apr 07 '17 at 15:43
  • You might be lucky enough to close using the `TASKKILL /T` option which may also close the child process. However this question is not a programming question and therefore off topic. – Compo Apr 07 '17 at 15:52

1 Answers1

1

You need to use a Job Object. See Working example of CreateJobObject/SetInformationJobObject pinvoke in .net? and Kill child process when parent process is killed

Do not try 'monitoring for one process', that leaves zombies when the monitoring crashes.

Community
  • 1
  • 1
Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569