Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Killing processes with listview (.net 2003)

Killing processes with listview (.net 2003)

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A
    wrote on last edited by
    #1

    I have created a program that lists all the processes running on the computer by using getprocesses then i have used a loop to list them all For each process Next Then i have made it so that each process is listed in a listview object. The problem i am having though is that i need to be able to use the process.kill method to exit the process that has been selected. How would i do this? If it is possible can you provide an example? Could i use the process.mainmodule.filename_(This just provides the filename/command line for the mainmodule of the program which is the process itself_) then give the filename(From the process.mainmodule.filename) to process.startinfo.filename. Then use the process.kill method, to exit the process? Any help would be much appreciated Thankyou! A*****

    X T 2 Replies Last reply
    0
    • A A

      I have created a program that lists all the processes running on the computer by using getprocesses then i have used a loop to list them all For each process Next Then i have made it so that each process is listed in a listview object. The problem i am having though is that i need to be able to use the process.kill method to exit the process that has been selected. How would i do this? If it is possible can you provide an example? Could i use the process.mainmodule.filename_(This just provides the filename/command line for the mainmodule of the program which is the process itself_) then give the filename(From the process.mainmodule.filename) to process.startinfo.filename. Then use the process.kill method, to exit the process? Any help would be much appreciated Thankyou! A*****

      X Offline
      X Offline
      xstoneheartx
      wrote on last edited by
      #2

      you can use this API function: Private Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Integer, ByVal uExitCode As Integer) As Integer for an example of what you want you can see this link: Terminate a process immediately in VB.NET[^]

      1 Reply Last reply
      0
      • A A

        I have created a program that lists all the processes running on the computer by using getprocesses then i have used a loop to list them all For each process Next Then i have made it so that each process is listed in a listview object. The problem i am having though is that i need to be able to use the process.kill method to exit the process that has been selected. How would i do this? If it is possible can you provide an example? Could i use the process.mainmodule.filename_(This just provides the filename/command line for the mainmodule of the program which is the process itself_) then give the filename(From the process.mainmodule.filename) to process.startinfo.filename. Then use the process.kill method, to exit the process? Any help would be much appreciated Thankyou! A*****

        T Offline
        T Offline
        TwoFaced
        wrote on last edited by
        #3

        This should help. I'm using VS2005 so I hope this will be the same for you.

        Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'Get the processes with the name 'qryspree'
            'You probably stored the process name in the listview so whatever item is selected
            'will tell you the process name to get
            Dim proc() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("qryspree")
        
            'Loop through processes found
            'Note: Finding a process by name returns an array so the loop just
            'ensures you kill each one with that name
            For Each instance As System.Diagnostics.Process In proc
                instance.Kill()
            Next
        End Sub
        

        As another option you could store the process id's when you add them to the listview. The process object will tell you the ID. You could store the name with the id in a hashtable.

        T 1 Reply Last reply
        0
        • T TwoFaced

          This should help. I'm using VS2005 so I hope this will be the same for you.

          Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              'Get the processes with the name 'qryspree'
              'You probably stored the process name in the listview so whatever item is selected
              'will tell you the process name to get
              Dim proc() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("qryspree")
          
              'Loop through processes found
              'Note: Finding a process by name returns an array so the loop just
              'ensures you kill each one with that name
              For Each instance As System.Diagnostics.Process In proc
                  instance.Kill()
              Next
          End Sub
          

          As another option you could store the process id's when you add them to the listview. The process object will tell you the ID. You could store the name with the id in a hashtable.

          T Offline
          T Offline
          TwoFaced
          wrote on last edited by
          #4

          I had another idea. Why not store the ID as a subitem in the listview. Here is an example.

          Public Class Form1
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          ListView1.View = View.Details
          ListView1.Columns.Add("Process", 150)
          ListView1.Columns.Add("ID", 75)
          '---Popullate listview1 with running processes
          For Each proc As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
          'Add ProcessName with a subitem as the ID
          ListView1.Items.Add(proc.ProcessName).SubItems.Add(proc.Id)
          Next
          End Sub

          Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              For Each item As ListViewItem In ListView1.SelectedItems
                  MsgBox(item.SubItems(1).text)
              Next
          End Sub
          

          End Class

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups