Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now