gpt4 book ai didi

excel - 如何通过 VBA 代码终止任务管理器进程?

转载 作者:行者123 更新时间:2023-12-02 08:50:56 25 4
gpt4 key购买 nike

我正在尝试通过 VBA 终止某些进程。我有一个连接到市场数据总线的专有对象。通过 RTD,我调用该对象来发布/订阅到总线。然而,有时连接会断开,我需要通过任务管理器终止该进程。有没有办法通过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
oProc.Terminate()
End If
Next

关于excel - 如何通过 VBA 代码终止任务管理器进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26303173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com