Kill Process if running longer than 15Min.

O

Oliver Schmidt

Hi everybody,
I like to kill a process (XLVIEW.EXE) on my W2K-Server, when it's
running longer than 15Min. Does anybody know a tool who could do this,
or could this be done with a batch-file? If so, how?
Thanks
Oliver
 
T

Torgeir Bakken (MVP)

Oliver said:
I like to kill a process (XLVIEW.EXE) on my W2K-Server, when it's
running longer than 15Min. Does anybody know a tool who could do this,
or could this be done with a batch-file? If so, how?

Hi

Here is a vbscript (save it with file extension .vbs):


sExePath = "C:\XlView800\XlView.exe"

Set oShell = CreateObject("WScript.Shell")

' start XlView
oShell.Run sExePath

' sleep for 15 minutes (in milliseconds)
WScript.Sleep 15 * 60 * 1000

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

Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = 'XlView.exe'")

' if XlView is in memory, it will be terminated
For Each oProcess in colProcessList
oProcess.Terminate()
Next
 
O

Oliver Schmidt

Thanks for this script,
but it is not exactly what I was looking for. The XLVIEW-Process is
started by a user on the terminalserver, and if the user doesn't shut
it down by himself I like to kill the process if it runs longer then
15Min.
Maybe this is also chalenging for you. Thanks a lot.
Oliver
 
T

Torgeir Bakken (MVP)

Oliver said:
Thanks for this script,
but it is not exactly what I was looking for. The XLVIEW-Process is
started by a user on the terminalserver, and if the user doesn't shut
it down by himself I like to kill the process if it runs longer then
15Min.
Maybe this is also chalenging for you. Thanks a lot.

Hi

Try this one:


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

' script will run forever
Do While True

Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = 'XlView.exe'")

If colProcessList.Count > 0 Then

' sleep for 15 minutes (in milliseconds)
WScript.Sleep 15 * 60 * 1000

' check if XlView.exe is still in memory
Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = 'XlView.exe'")

' if XlView is in memory, it will be terminated
For Each oProcess in colProcessList
oProcess.Terminate()
Next
End If

' sleep one minute before testing again
WScript.Sleep 60 * 1000
Loop
 

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

Top