process and Listbox

G

Guest

I am trying to list all the instances of notepad and some other specific apps
running on my computer using the code below:

Dim myPro() As System.Diagnostics.Process

myProcess = System.Diagnostics.Process.GetProcessesByName("notepad")

If myProcess.Length > 0 Then


For Each myCess As Process In myProc

If myCess.MainWindowTitle <> "" Then

listboxBrowsers.Items.Add(myCess.MainWindowTitle)

End If

Next

I do the above for each of the apps I want to appear in the listbox


The problem is, not all instances of all process shows up in my listbox.
(the same for vista's Task Manager also - not all instances of winword or
firefox shows up there either - even though the correct number shows up in
TM's application list)


I am trying to stop the process running in my listbox, by selecting a
process and then issueing a kill, but the code below is not working for me:

Dim myProcesses As System.Diagnostics.Process()

myProcesses =
Process.GetProcessesByName(listbox1.SelectedIndex.ToString())

Dim processCount As Integer = myProcesses.Length

For myProCount As Integer = 0 To processCount - 1

myProcesses(myProCount).Kill()

Next

When I press the button over this code nothing happens

I will be thankful for any help
 
J

josephshamiltons

I am trying to list all the instances of notepad and some other specific apps
running on my computer using the code below:

Dim myPro() As System.Diagnostics.Process

myProcess = System.Diagnostics.Process.GetProcessesByName("notepad")

If myProcess.Length > 0 Then

For Each myCess As Process In myProc

If myCess.MainWindowTitle <> "" Then

listboxBrowsers.Items.Add(myCess.MainWindowTitle)

End If

Next

I do the above for each of the apps I want to appear in the listbox

The problem is, not all instances of all process shows up in my listbox.
(the same for vista's Task Manager also - not all instances of winword or
firefox shows up there either - even though the correct number shows up in
TM's application list)

I am trying to stop the process running in my listbox, by selecting a
process and then issueing a kill, but the code below is not working for me:

Dim myProcesses As System.Diagnostics.Process()

myProcesses =
Process.GetProcessesByName(listbox1.SelectedIndex.ToString())

Dim processCount As Integer = myProcesses.Length

For myProCount As Integer = 0 To processCount - 1

myProcesses(myProCount).Kill()

Next

When I press the button over this code nothing happens

I will be thankful for any help

Saying that nothing happens or it doesn't work is evidence that you
really have not investigated the problem very much.

You need to step into the code and view each line to get a good idea
of what is going on. Hover you mouse over each one of the objects you
are creating to see what it is in them. For example: when you get the
processes by name, does this actually populate the object with all the
processes?

Anyway, I'm not trying to be hard on you but be sure you are using the
debugger to it's fullest. If you don't know how to set breakpoints
and step into the code, just ask and I will gladly explain it.
 
G

Guest

Ho Joe
As a matter of fact I have step into and out ofeach line of the code, and I
just about all the variables, including the arrays has "nothing" showing. I
am stumped
But thanks I will keep on tweaking
 
G

Guest

In your first listing, you appear to be interchanging freely, myPro, myProc
and myProcesses. Are these typos, or is your code really referencing three
separate objects.

In your second listing, you appear to have fixed the above, but you are
killing items from the list as you iterate through the list of processes.
This is always going to cause problems.
 
G

Guest

I think the listing problem is solved with the following code:

MyProc = System.Diagnostics.Process.GetProcessesByName("winword")


If MyProc.Length > 0 Then

For Each MyPro As Process In MyProc

If MyPro.MainWindowTitle <> "" Then
Me.listboxBrowsers.Items.Add(MyPro.ProcessName) '
End If

Next

The problem I am using the code below to to select a process(app) from a
list box, but I cannot sync up eash app in the listbox with the app I want to
delete. (If I had 2 or 3 version of the same app open I want to be able to
say close the 2nd one and the code I am using is not doing this:


For Each Myproc As Process In
Process.GetProcessesByName(listbox1.SelectedItem)
Myproc.CloseMainWindow()
Myproc.Close()
listbox1.Items.Remove(listbox1.SelectedItem)
Next
It is removing the last instance of winword regardless of which instance of
winword or any onther app that is selected in the listbox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top