Run bat file when starting an exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carnelain
Posts: 1
Joined: 08 Jan 2011 08:23

Run bat file when starting an exe

#1 Post by carnelain » 08 Jan 2011 08:26

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

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

Re: Run bat file when starting an exe

#2 Post by aGerman » 08 Jan 2011 09:06

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

Post Reply