|
MonitorApp
Monitoring applications. caled with the name of the application. should be caled from cscript form a command promt. (save this line in a file called monitor.bat and remenber to add a line at the end)
cscript thiscript.vbs %1
set oArgs=wscript.arguments
If oArgs.Count = 1 Then
Set wmiLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set svc = wmiLocator.Connectserver(".")
WScript.Echo "Looking for application: " & oArgs.item(0)
For i = 1 To 1000
Set oWin32processes = svc.InstancesOf("Win32_Process")
AppRunning = False
For Each oWin32process In oWin32processes
If oWin32process.Name = oArgs.item(0) Then
AppRunning = True
i = 1000
End If
Next
WScript.StdOut.Write Chr(13) & "Waiting for " & oArgs.item(0) & ": " & i & "/1000"
WScript.sleep (1000)
Next
WScript.Echo vbCRLF & "Found application: " & oArgs.item(0)
If AppRunning Then
WScript.Echo "Monitoring application: " & oArgs.item(0)
Do
WScript.sleep (2000) 'wait 2 sec before looking again
Set oWin32processes = svc.InstancesOf("Win32_Process")
AppRunning = False
For Each oWin32process In oWin32processes
If oWin32process.Name = oArgs.item(0) Then
AppRunning = True
End If
Next
Loop While AppRunning
Else
WScript.Echo "Application not found - exiting..."
End If
End If
WScript.Echo oArgs.item(0) & " closed - exiting..."
WScript.Quit
|