How do I use powershell to close a program after another program closes?

584 Views Asked by At

Is there a way to run Stop-Process after a specific program closes itself automatically?

I am trying to close my VPN client after my torrent client closes itself.

Any help is appreciated.

1

There are 1 best solutions below

3
Wasif On BEST ANSWER

You are looking for Wait-Process: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/wait-process?view=powershell-7

Wait-Process -Name "TorrentClientProcessName"
Stop-Process -Name "VPNClientProcessName "

This script waits until the Torrent client has exited and then closes VPNClient. You have to replace TorrentClientProcessName and VPNClientProcessName with their process names.