WMI Win32_Process Terminate Method with Listbox

  • Thread starter Peter Neuburger via .NET 247
  • Start date
P

Peter Neuburger via .NET 247

(Type your message here)

--------------------------------
From: Peter Neuburger

Hi Everybody,

I need some help with the WMI Terminate Method.

I have a Listbox where I get all the Process Information using the WMI Win32_process
class, that works fine.

Now I have a Stop Button that should terminate the process when I select it in the listbox
but I don?t really know how to write the Code, cause this don?t really work.

Code example:

Dim proc as ManagementClass("Win32_process")
Dim method() as Object = listbox1.items(listbox1.SelectedIndex), nothing)

try

if listbox1.SelectedIndex = -1 then
MessageBox.show ("Please select a Process")

else

proc.InvokeMethod("Terminate", method)

end if



Any Idea?s ???


thanks
 
R

Rob Teixeira [MVP]

Alternately, you could use the System.Diagnostics.Process class, and call
either CloseMainWindows or Kill.
You can also use the same Process class to return a list of running
processes.

-Rob Teixeira [MVP]
 
H

Herfried K. Wagner [MVP]

* Peter Neuburger via .NET 247 said:
I need some help with the WMI Terminate Method.

I have a Listbox where I get all the Process Information using the WMI Win32_process
class, that works fine.

Now I have a Stop Button that should terminate the process when I select it in the listbox
but I don?t really know how to write the Code, cause this don?t really work.

If youi don't get an answer here, you may want to turn to this group:

<URL:
 
K

Ken Tucker [MVP]

Hi,

Add a reference to system.management.dll. This will start notepad list all
the processes and owners and kill notepad when it finds it on the list.

Process.Start("notepad")
Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Process")

moReturn = moSearch.Get
For Each mo In moReturn
Dim args(2) As String
mo.InvokeMethod("GetOwner", args)
Dim strOut As String
strOut = String.Format("{0} - Owner {1}",
mo("Caption").ToString, args(0))
Trace.WriteLine(strOut)
If mo("Caption").ToString = "notepad.exe" Then
Dim objTerm(2) As Object
mo.InvokeMethod("Terminate", objTerm)
End If
Next

Ken
 

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

Top