Solved

How to monitor a Process in windows 2003 and Terminate IT.

Posted on 2008-10-20
4
298 Views
Last Modified: 2012-05-05
All,

I'm looking to write something in VB.Net (2005) that will monitor a process on a windows 2003 server and if it runs for more than X amount of time, terminate it.

In a nutshell, the server has a program that is launched from a remote PC to run a report and occasionally locks up. Since the user doesn't have access to the server, they keep trying to launch the report again and again but finally give up. I know from past experience I can terminate the process using pskill or taskill, I'm just looking for a way to automate it. Basically, if the "x process" runs for more than a minute, kill it...

Thanks in advance,

Mike
0
Comment
Question by:MiketheD
  • 2
4 Comments
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22765200
Will the application run on the server itself or from a remote location?

Kind regards,

Matthias Vance
0
 

Author Comment

by:MiketheD
ID: 22773612
Matthias,

Thanks for your reply... On the server...
0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 125 total points
ID: 22774569
Here's some example code. You just need to adjust it a bit, add a timer and a few minor changes.

Kind regards,

Matthias Vance
Public Class frmMain
 
    Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal handle As IntPtr, ByVal ms As Int32) As UInt32
 
    Private Sub CheckProcess(ByVal processName As String, ByVal allowedTime As Integer)
        Dim pl() As Process = Process.GetProcessesByName(processName)
        If (pl.Length > 0) Then
            Dim p As Process = pl(0)
            If WaitForSingleObject(p.Handle, 5000) > 0 Then
                p.Kill()
            End If
        End If
    End Sub
 
    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CheckProcess("calc", 5000)
    End Sub
End Class

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question