Solved Simple two program start and kill batch file

November 21, 2015 at 23:03:16
Specs: Windows 7
Hi all:)

I am new (today) to machine script. This is something I put together and will be trying tomorrow.

cd /d "C:\path"
Start Filename.bat

cd /d "H:\path"
Start Program.exe

ping -n 10 localhost 1> NUL
TASKLIST /v /fi "IMAGENAME eq program.exe" 2>&1 > NUL

taskkill /f /im cmd.exe /t

If all goes well, filename.bat will run. Then a program will run. CMD will then check for program.exe until not found (exited), then close CMD.

In this case program.exe does not work with start /wait

I am wondering if the check will slow down my machine if run for a few hours.

I am using Windows 7 x64, SSD, 16GB RAM and AMD 8350.

Considering inserting a small timeout, but seems silly.

Is there a way to slow down the check, but still close immediately if program.exe is closed? Other alternatives? Thanks :)

See More: Simple two program start and kill batch file

Report •

November 22, 2015 at 04:59:32
✔ Best Answer
I doubt the script will have a noticeable impact on your computer no matter how long you run it. You can replace the ping command with a timeout command:
timeout /t <seconds> > nul

Also, I think you'd have to use

TaskList /nh /fi "IMAGENAME eq program.exe" | find "program.exe" 2>&1 >nul

If you wanna exit the current script, there's a command for that too instead of using taskkill:


Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ

Report •

November 22, 2015 at 13:09:08
Thanks for your response!:)

That helped, much appreciated.

Here's the script in its final form / for documentation.

@echo off

cd /d "H:\path"

cd /d "C:\path"
xcopy /y "C:\path" "H:\path" /d
timeout /t 20


TaskList /nh /fi "IMAGENAME eq program.exe" | find "program.exe" 2>&1 > nul


Using NEQ in the ERRORLEVEL syntax allowed the script to detect negative values and would complete the loop until broken.

Report •

Related Solutions

Ask Question