Kill an unwanted process

This subroutine gives the programmer the ability to kill an unwanted process. For example, a student could be playing an inappropriate game. This subroutine will detect the game and destroy the process, thus exiting the game.

VB.NET

''' <summary>
''' Loops through the processes and kills a process if it is not wanted.
''' </summary>
''' <param name="strProcessToKill">The process you want killed.</param>
''' <remarks></remarks>

Public Sub killProcess(ByRef strProcessToKill As String)
    Dim proc() As Process = Process.GetProcesses
    For i As Integer = 0 To proc.GetUpperBound(0)
        If proc(i).ProcessName = strProcessToKill Then
            proc(i).Kill()
        End If
    Next
End Sub

' Example Usage.
killProcess("notepad")

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License