Setup timeout for commands in Windows .bat file

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

If you want to run a list of commands in a .bat file in Windows, such as

Shutdown -s -t 0

Sometimes, “c:\someapplication.exe” may freeze and do not respond. How can I setup timeout for my command “c:\someapplication.exe”, so that after a certain amount of time, I want windows to force close the application and continue the rest of the commands?
You could use a combination of ping and taskkill to do this:

start c:\someapplication.exe 
ping -n seconds 
taskkill /im someapplication.exe /f 
start c:\someapplication2.exe 
ping -n seconds 
taskkill /im someapplication2.exe /f 
Shutdown -s -t 0 /f

Just replace seconds in the ping command with the number of seconds you want to wait before attempting to close the process (enough time so if it’s still running it must have crashed). Then the rest of the app can continue until it is forced to shutdown. You can also do this:

start someapplication 
wait n seconds 
start someapplication2 
wait m seconds shutdown

Leave a Reply

Your email address will not be published. Required fields are marked *