[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

Visual basic Service to check if a process is running every 10 seconds and kill

I need to write a windows service that will kill another windows process, the servie will need to check if the process is running every 10 seconds or so.
Can someone give me a start on doing this?
2 Solutions
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, create a Windows Service project, add a Timer to the designer, set it interval to 10000 (10 seconds), then add this code to your Service.vb:
Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Start the timer

        ' Call immediately
        Timer1_Tick(Me, System.EventArgs.Empty)
    End Sub

    Protected Overrides Sub OnStop()
        'Stops the timer
    End Sub

    'This find the process that match the name (ex this will kill the task manager instances opened)
    Sub FindAndKill()
        Dim processNameToKill As String = "taskmgr"
        For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName(processNameToKill)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    End Sub
End Class

Open in new window

Or you can download the project from this link:

Inside you can customize the name of the process to be closed (killed).

I hope this help! :)
Mohamed AbowardaSoftware EngineerCommented:
Add System.Diagnostic namespace
Add timer and set its interval 10000

Add the following code in the timer tick event:
Dim processName As String = "PutProcessNameHere"

For Each p As Process In Process.GetProcesses
    If p.ProcessName = processName Then
    End If

Open in new window


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now