How can I kill task manager processes through VBA code?

后端 未结 4 1685
太阳男子
太阳男子 2020-11-29 11:57

I\'m trying to kill certain processes through VBA. I have a proprietary object that connects to a market data bus. Through RTD I call this object to pub/sub to the bus. Howe

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 12:23

    You can perform it, this way:

    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  'kill exe
        End If
    Next
    

提交回复
热议问题