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

Posted on 2011-04-23
Last Modified: 2012-05-11
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?
Question by:sykotex
    LVL 17

    Accepted Solution

    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! :)
    LVL 12

    Assisted Solution

    by:Mohamed Abowarda
    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

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now