0

I am running a command in command prompt and I want to kill it after 15 minutes. I don't care if it is completed or not. I don't want to have any human interaction to kill the running command such as someone has to press CTRL+C to kill it.

Is there a way to do it.

Please note I don;t want to use any third party tools or scripts.

Akash
  • 129
  • 1
  • 12
  • 2
    This seems like a duplicate of this question: http://stackoverflow.com/questions/11121424/need-to-run-an-exe-then-kill-it-after-10-seconds-and-move-to-next-command-in?rq=1 –  Jun 05 '15 at 21:27
  • Possible duplicate of [Need to run an .exe, then kill it after ~10 seconds and move to next command in batch file](http://stackoverflow.com/questions/11121424/need-to-run-an-exe-then-kill-it-after-10-seconds-and-move-to-next-command-in) – Andreas Apr 20 '17 at 11:43

3 Answers3

3
start forfiles /s
timeout /t 5
Taskkill /im forfiles.exe /f

is one way.

2

Did you mean something like that ?

@echo off
Tracert www.google.com
timeout /t 900 /nobreak >NUL
Taskkill /im cmd.exe /f

Edit : based on the blueray's comment :

how can I put this command in a single line to use in CMD?

Tracert www.google.com & timeout /t 900 /nobreak >NUL & Taskkill /im cmd.exe /f
Hackoo
  • 15,943
  • 3
  • 28
  • 59
0

May be this could help

start your-command-here

ping 127.0.0.1 -n 120 > NUL

taskkill /im cmd.exe /f

Explanation:

start: this command starts executing your command

ping: it pings your local machine(ip : 127.0.0.1) for 120 sec and >NUL redirects the output to nowhere else the output of ping command will be displayed on the cmd screen

taskkill: it is used to kill any task

/im: image name of the process to be terminated. if the command is running on cmd then cmd.exe or any program that you need to kill.

Hope it helps.