Kill a task manager process

Share this post
FaceBook  Twitter  Mixx.mn     


To Kill a task manager process , use following code:
Steps:
1) Get an object from winmgmts root\CIMV2

2) Execute SQL to retrieve all process from process

3) Kill all process

Code:

 Dim objWMIService, colItems,OSname,strComputer
 
          strComputer = "."
          strProcessToKill="Winword.exe"
'1) Get an object from winmgmts root\CIMV2'         
          Set objWMIService = GetObject("winmgmts:" _
              & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'2) Execute SQL to retrieve all process from process             
          Set colProcessList = objWMIService.ExecQuery _
              ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

'3) Kill all process'
          For Each objProcess in colProcessList
              objProcess.Terminate()
          Next