954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Vb2012 ive got a Problem agian

So here's Wat im trying to do
Ive got 2 List boxes 1 Shows Processes other one is for Storage
Anyway that's not important
Im trying to Kill all the Processes wat are stored in Listbox 2
I had to add .exe at List for Listbox 2
But still not working ???
The problem is its not removing the File names that are stored

ProgressBar1.Increment(1)
        Process.EnterDebugMode()
        If ProgressBar1.Value = ProgressBar1.Maximum Then  
            For Each proc In Form3.ListBox2.Items
                Dim ppdd() As Process = System.Diagnostics.Process.GetProcessesByName(proc.ToString)
                For Each p As Process In ppdd
                    p.EnterDebugMode()
                    p.Kill()
                    p.LeaveDebugMode()
                Next
            Next 
            Process.LeaveDebugMode()
            Timer2.Stop()
            MessageBox.Show("Removal was Succesfull", "Protocol Terminated", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ProgressBar1.Value = 0
            Button4.Enabled = True
        End If
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

>>The problem is its not removing the File names that are stored
If it is for ListBox2, to have items removed, you need to loop backwards thru the ListBox and remove the .Items.

With ListBox2
            For i As Integer = .Items.Count - 1 To 0 Step -1
                .Items.Remove(.Items(i))
            Next
        End With

Looping forward and removing items will cause it to crash since it is looking for the .Count that was first set, and it constantly changes to .Count -=1.

Hope this helps.:)

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

:D No you are not understanding im not trying to remove Items From List box
Im trying to Loop through them so That They will be seen as a Process To Remove in Memorty
Its Kinda like a Storage to pick a process and save it then you can remove them

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

>>No you are not understanding...
My.Apologies?for not understanding and good.luck since I am out of possible suggestions/solutions regarding this thread.

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

No man its okay
Okay so Ive got it working but the Example very advanced
or doesnt really make much sense

For Each proc In Form3.ListBox2.Items
                Dim ppdd() As Process = System.Diagnostics.Process.GetProcessesByName(proc.ToString.ToLower.Split(".")(0))
                For Each p As Process In ppdd
                    p.Kill()
                Next
            Next
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

The

(proc.ToString.ToLower.Split(".")(0))


doesnt make sense why is it needed becuase Removing Normal Programs like this does not need the Backend

Dim BTProcess() As Process = System.Diagnostics.Process.GetProcessesByName("BtTray")
            For Each p As Process In BTProcess
                p.Kill()
            Next
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

:'(So please Codeorder Help Me

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

:'( I don't know how!!! :'(

I did however noticed that your are Dim 'ing inside a For/Next loop. From my perspective, I think that it is overworking someone's p.c. to the bone by constatly Dim 'ing something.
Why not Dim just before the For/Next and reuse that Variable in the loop, instead of constantly setting new Variables ?

Hope it helps.:)

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Dude it works
I just dont understand how it works ????
:-O

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

THis Piece of Code is Not making sense but it does work i just wana understand how it Works

proc.ToString.ToLower.Split(".")(0))

:@

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

Post the code that loads the .Processes in your ListBox.
I'll use the code you currently have here and will try to "make sense" of how it works, then will post a possible "understand.Me.NT":D of how it works.:)

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Okay Here it is. This is the file Where it is Stored and reads it

Dim WoofRead = New IO.StreamReader(MySettingfile)
            While (WoofRead.Peek() > -1)
                Form3.ListBox2.Items.Add(WoofRead.ReadLine)
            End While
            WoofRead.Close()
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

THis is the Process adder from listbox 1 to listbox 2(aka Storage(File))

Try
            ListBox2.Items.Add(ListBox1.SelectedItem.ToString & ".exe")
        Catch tt As Exception
        End Try

And Here i save the List box 2 Items To Storage File

If Me.CheckBox1.Checked Then
            Dim myCoolWriter As New IO.StreamWriter(MySettingfil)
            For i As Integer = 0 To ListBox2.Items.Count - 1
                myCoolWriter.WriteLine(ListBox2.Items(i).ToString)
            Next
            myCoolWriter.Close()
            Me.Dispose()
        Else
            Dim myCoolWriter As New IO.StreamWriter(MySettingfil)
            For i As Integer = 0 To ListBox2.Items.Count - 1
                myCoolWriter.WriteLine(ListBox2.Items(i).ToString)
            Next
            myCoolWriter.Close()
        End If
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

:-/Hope It Helps you to Understand I can also give the Project To you:S

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

;)But only the Build File not the code ....

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

Then Maybe You will Understand More Easily:)

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

Okay Ive got a New Problem When i load The Storage file Into Listbox 2 it adds Every item twice becuase i have to load the File in Form1 and Form 3 is there any workaround..

Here's the code

Dim WoofRead = New IO.StreamReader(MySettingfile)
            While (WoofRead.Peek() > -1)
                Form3.ListBox2.Items.Add(WoofRead.ReadLine)
            End While
            WoofRead.Close()
VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

Okay Sory Here's updated code It's Working Now , atleast for now

ListBox2.Items.Clear()
        Dim WoofRead = New IO.StreamReader(MySettingfil)
        While (WoofRead.Peek() > -1)
            ListBox2.Items.Add(WoofRead.ReadLine)
        End While
        WoofRead.Close()


:D Sorry For asking my bad:D

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

I've been out all day, really tired, though I still noticed that you have not posted the code that loads the .Processes into your ListBox?

Since that was too much of a difficult task for you to do, even after 100+attempts of posting:D, why not just post one or 2 of the ListBox.Items(Processes) in your next post.

I mostly need to see how they are loaded into your ListBox, If FullPath, ElseIf only FileName, etc.. This because I am also a bit confused on how you can .Split by the "." and still get a For/Next loop out of one .Item(Process?).

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 
Private Sub UpdateProcessList()
        ListBox1.Items.Clear()
        Dim p As System.Diagnostics.Process
        For Each p In System.Diagnostics.Process.GetProcesses()
            ListBox1.Items.Add(p.ProcessName)
        Next
        ListBox1.Sorted = True
        Label3.Text = "Processes : " & ListBox1.Items.Count.ToString
        Label4.Text = "Processes : " & ListBox2.Items.Count.ToString
    End Sub


Ill try not to use more space in the thread :D

VB 2012
Junior Poster
155 posts since Jul 2010
Reputation Points: 15
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: