Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for a process to start and terminate

Status
Not open for further replies.

mhmallory

Technical User
Jan 23, 2003
11
0
0
US
I have been attempting to write some unattended applications install on XP. The problem is that during installation of some applications, they attempt to start "iexplorer" or "chrome". Is there an example of a background script that will wait for either process to start, and immediately terminate either the process in a loop? What I've done so far eats up too much CPU time, or causes a memory leak.

TIA
mhmallory
 
Option Explicit
On Error Resume Next
dim strcomputer
dim objwmiservice
dim colmonitoredprocesses
dim datstartdate
dim objlatestprocess

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 1 where TargetInstance isa 'Win32_Process'")

datStartdate = Now()


'msgbox "start of monitor"

Do While cint(DateDiff("s",datStartdate,Now())) < 300
Set objLatestProcess = colMonitoredProcesses.NextEvent
Wscript.Sleep 6000 'here we go again, yawn, yawn
If objLatestProcess.TargetInstance.Name = "IEXPLORE.EXE" Then
WScript.Sleep 6000 ' yes i know i should be shot
objLatestProcess.TargetInstance.Terminate
Exit Do
End If
Loop

'msgbox "out of loop"
Set objLatestProcess = Nothing
Set colMonitoredProcesses = Nothing
Set objWMIService = Nothing

Wscript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top