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

gNome
gNome used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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
Aman SubhanOracle Database Administrator

Commented:
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

This VBScript should work.  
Set objShell = CreateObject("Wscript.Shell")
strEXE="calc.exe"
objShell.Run strEXE
wscript.sleep 300000
objShell.Run "cmd /c taskkill /f /im "&strEXE

Open in new window

Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

Commented:
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..

Author

Commented:
Excellent solution - thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial