locked
Closing an App by its process name. RRS feed

  • Question

  • Hello,

        I'm looking for a simple and effective code to add to a button
    for closing an application by it's process name.

       If this is possible without having to play around with HWind I would
    be thankful for an example.

       Ultimately, when the user hits the button, I would like every instance
    of that application to shut down.

       This means scanning the process list for the number of open instances
    of that application. Unless there is a better way.

    Cheers and thanks.
    Thursday, November 10, 2005 2:48 PM

Answers



  • Private
    Sub KillAllProcessByName(ByVal NameOfProcess As String)

    Dim ProcessArray() As Process = Process.GetProcessesByName(NameOfProcess)

    For x As Integer = 0 To ProcessArray.Length - 1

    ProcessArray(x).Kill()

    Next

    End Sub
     


    Thursday, November 10, 2005 3:11 PM

All replies



  • Private
    Sub KillAllProcessByName(ByVal NameOfProcess As String)

    Dim ProcessArray() As Process = Process.GetProcessesByName(NameOfProcess)

    For x As Integer = 0 To ProcessArray.Length - 1

    ProcessArray(x).Kill()

    Next

    End Sub
     


    Thursday, November 10, 2005 3:11 PM
  • Thank you, although the code you presented will work in some instances, I believe
    that the following code is slightly more direct.

    Imports System.Diagnostics
    Public Class Killer
    Private Sub Shield_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    For Each p As Process In Process.GetProcesses()
    If p.ProcessName = "iexplore" Then p.Kill()
    Next
    End Sub
    End
    Class

    Thursday, November 10, 2005 5:48 PM
  • always more than one way to skin a cat!
    Thursday, November 10, 2005 5:51 PM
  • hey Synergy,

    where do you paste that code?
    Saturday, August 23, 2008 5:49 AM