Batch file that will kill after 10sec process if the process

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JohnCZ
Posts: 1
Joined: 02 Jul 2015 01:41

Batch file that will kill after 10sec process if the process

#1 Post by JohnCZ » 02 Jul 2015 01:47

Dear all,
I have problem with application. If the application starts everything is ok and the memory of application is about 150MB. Time to time the application doesn't start (not showing the visualization) but in taskbar there is running the application with low memory about 30MB. If I kill the process in taskbar and run again everything is ok. I do not know how to set batch file to kill process after 10s and if the application used low memory.

BR
JohnCZ

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch file that will kill after 10sec process if the pro

#2 Post by Squashman » 02 Jul 2015 09:23

Which version of Windows?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file that will kill after 10sec process if the pro

#3 Post by aGerman » 02 Jul 2015 11:01

That may work for you:

Code: Select all

@echo off &setlocal
set "process=program.exe"

start "" "%process%"
timeout /t 10 /nobreak

for /f tokens^=9^ delims^=^" %%i in (
  'tasklist /nh /fo csv /fi "imagename eq %process%"'
) do for /f %%j in ("%%i") do for /f "tokens=1,2 delims=.," %%k in ("%%j") do (
  if %%k%%l lss 50000 (
    taskkill /im %process%
    start "" "%process%"
  )
)

You have to customize variable process in line 2 and you may have to define the fully qualified path in the two START command lines e.g.

Code: Select all

start "" "C:\path of the program\%process%"


Regards
aGerman

Post Reply