我怎样才能通过VBA代码杀死任务pipe理器进程?

我试图通过VBA杀死某些进程。 我有一个连接到市场数据总线的专有对象。 通过RTD,我把这个对象称为pub / sub到总线。 但有时连接会下降,我需要通过任务pipe理器来终止进程。 有没有办法通过VBA杀死一个进程?

谢谢

尝试使用此代码,源自此处

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 errReturnCode = oProc.Terminate() End If Next 

再看一个例子:

 Sub Test() If TaskKill("notepad.exe") = 0 Then MsgBox "Terminated" Else MsgBox "Failed" End Sub Function TaskKill(sTaskName) TaskKill = CreateObject("WScript.Shell").Run("taskkill /f /im " & sTaskName, 0, True) End Function