Link to home
Start Free TrialLog in
Avatar of gNome
gNomeFlag for Afghanistan

asked on

DOS script to kill if .bat file takes longer than 5 minutes to run

I have a simple script that calls an executable and I need to wrap a timeout around the process so that the process ends if it takes longer than 5 minutes to run.  I need to do it procedurally within the bat file without the schedule task option.e.g.

If I call myscript.bat and it takes longer than 5 minutes to execute - kill the running process.  Is there simple vbs that would allow me to manage the time it shoudl take to run the script?
Avatar of tniemetz
tniemetz
Flag of United States of America image

The Task Scheduler has the ability to set conditions that may help (maximum execution time). Here is a link to TS info (Vista and up).

http://technet.microsoft.com/en-us/library/cc507860.aspx
Avatar of Aman Subhan
Aman Subhan

its simple....
make a script like this..

then u may get 300 seconds of waiting time that is 5 min...
after this time the executable will end process!!!

myscript.exe
sleep 300
kill myscript.exe
pause

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mani's script will not work, because when a batch file calls an executable it waits for the executable to return before continuing.

TakedaT is on the right track, I used to use VBS in WSH files on windows almost exclusively and had gotten quite adept at using the execution command to run DOS commands but due to the need to run more of them I am now mainly a batch writer, I'll see fi I can find an old script, something says that there is a bit more you'll want to do than his 5 lines of code..
Avatar of gNome

ASKER

Excellent solution - thanks!