473,467 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Terminate process in wmi with vb.net

I cant seem to figure out how to terminate a process in vb.net i can do it
using vbscript and wmi but terminate doesnt seem to exist in the available
classes for wmi under vb.net
Nov 20 '05 #1
3 13758
Hi,

You can do it without the wmi. Take a look at the process class.

' To list processes

Dim p As Process

For Each p In Process.GetProcesses

Debug.WriteLine(p.ProcessName)

Next

' to kill a process

'p.Kill()

Ken

----------------

"Keith Grefski" <ma********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I cant seem to figure out how to terminate a process in vb.net i can do it
using vbscript and wmi but terminate doesnt seem to exist in the available
classes for wmi under vb.net

Nov 20 '05 #2
that doesnt seem to work remotely

here is the code i am trying to use now, i get a cast error now

Function WMIKill(ByVal Server As String, ByVal sProcess As String)

Dim strMoniker, strQuery As String

Dim colProcesses As Management.ManagementObjectSearcher

Dim refProcess As Management.ManagementObject

colProcesses = New Management.ManagementObjectSearcher("SELECT * FROM
Win32_Process WHERE Handle = '" & sProcess & "'")

colProcesses.Scope = New Management.ManagementScope("\\" & Server &
"\root\cimv2")

If colProcesses.Get.Count = 0 Then

ListOutPut.Items.Add(sProcess & " - Not found on " & Server)

Else

'there are some matching process, so loop through and kill

For Each refProcess In colProcesses.Get

If refProcess.InvokeMethod("Terminate", refProcess("handle")) = 0 Then

ListOutPut.Items.Add("(PID " & refProcess("Handle") & ") " & _

refProcess("Name") & _

" Terminated on - " & Server)

Else

ListOutPut.Items.Add("Unable to terminate - " & _

refProcess("Name") & " on " & Server)

End If

Next

End If

End Function

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Hi,

You can do it without the wmi. Take a look at the process class.

' To list processes

Dim p As Process

For Each p In Process.GetProcesses

Debug.WriteLine(p.ProcessName)

Next

' to kill a process

'p.Kill()

Ken

----------------

"Keith Grefski" <ma********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I cant seem to figure out how to terminate a process in vb.net i can do it using vbscript and wmi but terminate doesnt seem to exist in the available classes for wmi under vb.net


Nov 20 '05 #3
I figured it out. Here's the code i used

Function WMIKill(ByVal Server As String, ByVal sProcess As String)

Dim colProcesses As Management.ManagementObjectSearcher

Dim colObserver As New Management.ManagementOperationObserver

Dim refProcess As Management.ManagementObject

colProcesses = New Management.ManagementObjectSearcher("SELECT * FROM
Win32_Process WHERE Handle = '" & sProcess & "'")

colProcesses.Scope = New Management.ManagementScope("\\" & Server &
"\root\cimv2")

If colProcesses.Get.Count = 0 Then

Else

For Each refProcess In colProcesses.Get

refProcess.InvokeMethod(colObserver, "Terminate", Nothing)

Next

End If

End Function

"Keith Grefski" <ma********@hotmail.com> wrote in message
news:OW*************@TK2MSFTNGP12.phx.gbl...
that doesnt seem to work remotely

here is the code i am trying to use now, i get a cast error now

Function WMIKill(ByVal Server As String, ByVal sProcess As String)

Dim strMoniker, strQuery As String

Dim colProcesses As Management.ManagementObjectSearcher

Dim refProcess As Management.ManagementObject

colProcesses = New Management.ManagementObjectSearcher("SELECT * FROM
Win32_Process WHERE Handle = '" & sProcess & "'")

colProcesses.Scope = New Management.ManagementScope("\\" & Server &
"\root\cimv2")

If colProcesses.Get.Count = 0 Then

ListOutPut.Items.Add(sProcess & " - Not found on " & Server)

Else

'there are some matching process, so loop through and kill

For Each refProcess In colProcesses.Get

If refProcess.InvokeMethod("Terminate", refProcess("handle")) = 0 Then

ListOutPut.Items.Add("(PID " & refProcess("Handle") & ") " & _

refProcess("Name") & _

" Terminated on - " & Server)

Else

ListOutPut.Items.Add("Unable to terminate - " & _

refProcess("Name") & " on " & Server)

End If

Next

End If

End Function

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Hi,

You can do it without the wmi. Take a look at the process class.

' To list processes

Dim p As Process

For Each p In Process.GetProcesses

Debug.WriteLine(p.ProcessName)

Next

' to kill a process

'p.Kill()

Ken

----------------

"Keith Grefski" <ma********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I cant seem to figure out how to terminate a process in vb.net i can do it using vbscript and wmi but terminate doesnt seem to exist in the available classes for wmi under vb.net



Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: abovetreeline | last post by:
Hi, How to make javascript terminate a win32_process? vbscript will terminate a named process with the following code: strcomputer = "." Set objwmiservice = GetObject("winmgmts:" _ &...
3
by: Peter Neuburger via .NET 247 | last post by:
(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...
5
by: Benny | last post by:
I have a ASP.NET webservice and it is configured to run in a web garden with multiple processes. Whan a process in the garden is launched, I want the process to create a background thread. When...
8
Atran
by: Atran | last post by:
Hello, in my pc, there is some processes cant terminate. When I click to a process end now, then click yes, after: pc show a error messagebox that cannot terminate that proecess. So How I can...
1
by: Justin | last post by:
We had a load that failed. Now we have a pending load. When executing load terminate, we receive the following error: db2 load terminate SQL0104N An unexpected token "terminate" was found...
2
by: cnsabar | last post by:
Hi., I am using the following code to terminate the any process by giving the process name as input... use Win32::Process::List; use Win32::OLE; $Win32::OLE::Warn = 3; $P =...
0
by: cnsabar | last post by:
Hi., I need a Perl script to terminate the any running process in server. by specifying computer name and process name.. I have the following code to terminate the any process by specifying...
1
by: thunder54007 | last post by:
hi, here is my script: import win32con import time import wmi c = wmi.WMI() for process in c.Win32_Process(name = "notepad.exe"): print process.ProcessId, process.Name process.Terminate ()
2
by: Smokey Grindel | last post by:
Is there anyway to check if an external process is running, then terminate it if it is? my problem right now is in my installer the user might try to upgrade while the program is running... I want...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.