djturizmo
asked on
VBS script to kill process after x amount of seconds
I have a program that opens up microsoft word. Sometimes that program hangs, which means that Microsoft word is still open. I would like to get a script that will run lets say every 5 minutes and check to see how long Microsoft word has been open. If it has been open for lets say 15 minutes or more, I want it to email me. I have figured out how to make things email me but I have not figured out how to have it calculate how long a program has been open and then perform an action based on the result.
Any help would be greatly appreciated.
Any help would be greatly appreciated.
ASKER
What is the 48 for?
ASKER
OK this is what I have so far. Can you help with it? This script runs with no errors but It seems like it doesn't return and instance of winword.exe
strComputer = "."
strWaitTime = 15
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_PerfFormattedData_Pe rfProc_Pro cess Where Name = 'WINWORD.EXE'")
If ElapsedTime > strWaitTime Then
Set objEmail = CreateObject("CDO.Message" )
objEmail.From = "TEST@TESTcom"
objEmail.To = "TEST@TEST.com"
objEmail.Subject = "Status Hung"
objEmail.Textbody = "Status Hung"
objEmail.Configuration.Fie lds.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fie lds.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"blah.blah.local"
objEmail.Configuration.Fie lds.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fie lds.Update
objEmail.Send
End If
strComputer = "."
strWaitTime = 15
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_PerfFormattedData_Pe
If ElapsedTime > strWaitTime Then
Set objEmail = CreateObject("CDO.Message"
objEmail.From = "TEST@TESTcom"
objEmail.To = "TEST@TEST.com"
objEmail.Subject = "Status Hung"
objEmail.Textbody = "Status Hung"
objEmail.Configuration.Fie
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fie
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"blah.blah.local"
objEmail.Configuration.Fie
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fie
objEmail.Send
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help, that did the trick.
Open in new window