1

I have a batch file that starts two programs :

@echo off
start "" "C:\Program Files (x86)\Kodi\Kodi.exe"
start "" "C:\Program Files\OpenVPN\bin\openvpn-gui.lnk"

Now when i close program "Kodi", i want that it close automatically first the task "openvpn-gui.exe" and then "openvpn.exe"

Thank you !

Hackoo
  • 18,337
  • 3
  • 40
  • 70
hakky
  • 11
  • 1

2 Answers2

1

Not tested, but give a try :

@echo off
Title Killing two process automatically after closing one program manually
set "RunningProcess=Kodi.exe"
set "Process2Kill=openvpn-gui.exe openvpn.exe"
tasklist /fi "imagename eq %RunningProcess%" /nh |find /i /c "%RunningProcess%"|findstr "^1$" >nul 
If "%Errorlevel%" EQU "1" (
    For %%a in (%Process2Kill%) do Call :KillProcess "%%a"
) else (
    echo %RunningProcess% is still running 
)
pause & exit

:KillProcess
Taskkill /f /im "%~1">nul 2>&1
goto :eof
Hackoo
  • 18,337
  • 3
  • 40
  • 70
1

What about this:

start "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe"
start "" "C:\Program Files\OpenVPN\bin\openvpn.exe"
start "" /WAIT "C:\Program Files (x86)\Kodi\Kodi.exe"
taskkill /IM "openvpn.exe"
taskkill /IM "openvpn-gui.exe"
aschipfl
  • 33,626
  • 12
  • 54
  • 99