@echo off
:: (c)2015 sorin@toXX.guru
setlocal
:: echo Checking if EDI (Gedi_dsk.exe) runs for more than 15 min and disconect if true
for /F "tokens=1" %%t in ('tasklist /FO TABLE /FI "CPUTIME gt 00:15:00" /FI "IMAGENAME eq Gedi_dsk.exe"') do (
if "%%t" == "Gedi_dsk.exe" (rasdial /disconnect >NUL )
)
::the same result can be obtained using pslist:
::for /F "tokens=11 delims=: " %%f in ('"pslist Gedi_dsk 2>NUL"') do (
::if %%f geq 15 ( rasdial /disconnect >NUL )
::)
:: echo if EDI is not started wait a few seconds try again, then disconnect if it is still not there
for /F "tokens=1" %%t in ('tasklist /FI "IMAGENAME eq Gedi_dsk.exe" 2>NUL') do (
if NOT "%%t" == "Gedi_dsk.exe" (
:: echo program not running wait a few seconds and check again
ping -n 5 -w 1000 1.1.1.1 >NUL
for /F "tokens=1" %%t in ('tasklist /FI "IMAGENAME eq Gedi_dsk.exe" 2>NUL do (
if NOT "%%t" == "Gedi_dsk.exe" ( rasdial /disconnect >NUL )
)
)
)
endlocal