Solved

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

Posted on 2008-10-20
4
296 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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