Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.Net] Handling multiple processes at once, using for each and arrays

Hello,

In this tutorial I will explain you how you can kill(you can do whatever you want, but i'll be using kill) multiple processes at once.

I'll be using:

- one Listview
- one Contextmenustrip

Okey,

First draw the items into the form.

Then, on top, under Public Class Form1 add:
Code
Dim countitems As Integer = 0

Then in Form1_Load paste:
Code
For Each p As Process In Process.GetProcesses
    Dim lviList As New ListViewItem(New String() {p.ProcessName.ToString}) ' create a new line
    ListView1.Items.Add(lviList) 'add it
    countitems = countitems + 1
  Next

Click the contextmenu you previously added and add a new item name it Termiate (or whatever you want).
Okey, go into the designer, select the listview.

Set the next settings:

CheckBoxes = True(To put checkboxes infront of the items, you can use multiselect (Hit Ctrl and select multiple items, but I prefer checkboxes))
View = Details
ContextMenuStrip = ContextMenuStrip1(So where ever you right click (inside the listview ofcourse), the contextmenustrip will appear)

Add the following code to the contextmenu item.

Code
Dim index As Integer = 0 ' count
  Dim str(0 To countitems) As String ' Max
  Array.Clear(str, str.GetLowerBound(0), str.Length) ' clear the array
  For Each lvi As ListViewItem In ListView1.CheckedItems ' for each checkbox checked
    str(index) = lvi.Text ' set array
    index = index + 1 ' index + 1 for next array
  Next
  For Each p As Process In Process.GetProcesses
    For i = 0 To index - 1 ' Loop through all process strings we want to kill
    If p.ProcessName.Contains(str(i)) Then ' if its equal
    p.Kill() ' kill it
    End If
    Next
  Next

You can use multiselect to, you just have to change:
Code
For Each lvi As ListViewItem In ListView1.CheckedItems
into
Code
For Each lvi As ListViewItem In ListView1.SelectedItems

and ofcourse, leave the checkboxes out.

Press F5 and check it out.

Fully programmed and wrote by me, reply's are welcome :)
FR1908
Variable += Value

Simple really.
(Dec 11, 2010 08:50 AM)ident Wrote:  Variable += Value

Simple really.

Nice explanation! /sarcasm.
FR1908
I was just pointing it out. Back when i started programming i learned variable basics before Process.GetProcesses Method.
(Dec 11, 2010 09:03 AM)ident Wrote:  I was just pointing it out. Back when i started programming i learned variable basics before Process.GetProcesses Method.

Lol you are comparing variables with processes? Like comparing a dog with a cupcake.
FR1908
I can see the point went straight over your head. Should of guessed it really.
(Dec 11, 2010 09:07 AM)ident Wrote:  I can see the point went straight over your head. Should of guessed it really.

Well done, can you now get the fk out of my thread?
FR1908


Possibly Related Threads...
Thread / Author Replies Views Last Post
by ByteDoktorFeb 26, 2025 01:24 PM 0 147 Feb 26, 2025 01:24 PM
Last Post: ByteDoktor
[.NET] by pzychonautJun 8, 2023 05:03 PM 5 174 Jun 8, 2023 05:03 PM
Last Post: padrino
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 237 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad