launch batch file when program launches

  • Thread starter Thread starter RGivens
  • Start date Start date
R

RGivens

I want to set up a batch file to run when a particular
executable is run. I have a Windows 2000 Server SP4 with
a program on it. When the executable for that program
launches I want it to run a batch file. How would I go
about doing that?

-Thank you
 
RGivens said:
I want to set up a batch file to run when a particular
executable is run. I have a Windows 2000 Server SP4 with
a program on it. When the executable for that program
launches I want it to run a batch file. How would I go
about doing that?

-Thank you

call the executable itself from a batch file after the commands in your
batch file have run.
 
Actually I want the batch file to launch when the
executable is run. I don't want to start the executable
from within the batch file. Is there anyway for the
machine to realize the executable has been launched, like
an alert in performance monitor, so that I can run the
batch file.

Thanks for your help.
 
RGivens said:
I want to set up a batch file to run when a particular
executable is run. I have a Windows 2000 Server SP4 with
a program on it. When the executable for that program
launches I want it to run a batch file. How would I go
about doing that?

-Thank you
Hi

A variant of the script found here (Monitor Process Creation):
http://www.microsoft.com/technet/community/scriptcenter/monitor/default.mspx


This script will launch calc.exe when notepad.exe is started.
Remove the "Exit Do" line if you want it to run "forever".


'--------------------8<----------------------
' process to look for
strProcessName = "notepad.exe"

' command to launch when strProcessName is started.
strCmd = "calc.exe"

Set objShell = CreateObject("WScript.Shell")

strComputer = "." ' use "." for local computer
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& "within 1 where TargetInstance isa 'Win32_Process'" _
& "and targetInstance.Caption = '" & strProcessName & "'")

Do While True
' wait for process to show up
Set objLatestProcess = colMonitoredProcesses.NextEvent

objShell.Run strCmd, 1, True
' for the command above, set second parameter to 0 if you want to
' hide the batch file console
' for the command above, set third parameter to False if you don't
' want to wait for the batch file to finish

' remove line below if you want to run forever
Exit Do
Loop
'--------------------8<----------------------


WSH 5.6 documentation (local help file) can be downloaded from here
if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top