Solved

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

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

20 Experts available now in Live!

Get 1:1 Help Now