windows task scheduler: how trigger task then program has closed?

4.6k Views Asked by At

I'm building a specific task.

I need to track when a program ends, make report and analyze it. So, I want to create a schedule for it.

For example, I have process called testing.exe, and I want to check for it's log after it finishes job. I have analyze.bat file. I just need something to run it, just after testing.exe finishes it's job and closes.

I can't change anything in program code, so I believe, that task scheduler is the only way.

Help me please

1

There are 1 best solutions below

0
On

Task Scheduler is not even required for this! It can be done under just batch!

@echo off
set batdir=____________
:begin
tasklist /FI "IMAGENAME eq testing.exe" 2>NUL | find /I /N "testing.exe">NUL
if "%ERRORLEVEL%"=="0" goto start
goto begin
:start
tasklist /FI "IMAGENAME eq testing.exe" 2>NUL | find /I /N "testing.exe">NUL
if "%ERRORLEVEL%"=="0" goto start
start %batdir%\analyze.bat

Just replace _________ with the directory of analyze.bat and it should work. What it does is: it first waits for testing.exe to start. If it started or was already on, it switches and now waits for testing.exe to close. Once it closes, it starts analyze.bat which is exactly what you wanted without the need of Task Scheduler. Hope I helped!