How can I kill task manager processes through VBA code?

Try with this code

Dim oServ As Object
Dim cProc As Variant
Dim oProc As Object

Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("Select * from Win32_Process")

For Each oProc In cProc

    'Rename EXCEL.EXE in the line below with the process that you need to Terminate. 
    'NOTE: It is 'case sensitive

    If oProc.Name = "EXCEL.EXE" Then
      MsgBox "KILL"   ' used to display a message for testing pur
      oProc.Terminate()
    End If
Next

Leave a Comment