Page 1 of 1

Run bat file when starting an exe

Posted: 08 Jan 2011 08:26
by carnelain
Hi all,

I am still a bit new to writing batch files so my question might be a bit dumb. Here comes:
Is it possible to run a batch file only if another exe (for instance notepad.exe) starts? And if so how would I do this?

Kind Regards,

Carnelain

Re: Run bat file when starting an exe

Posted: 08 Jan 2011 09:06
by aGerman
Possible? Yes, but not a good idea. You need a process (e.g. a second batch file) that is observing permanently if notepad is running or not running.

Code: Select all

@echo off &setlocal
set "processname=notepad.exe"

:loop
tasklist /fi "imagename eq %processname%" |find /i "%processname%" >nul ||goto loop

echo notepad is running
pause


Better idea: use something like a starter batch.

Code: Select all

@echo off &setlocal
start notepad.exe

:: your stuff here


Regards
aGerman