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