Dim objList As WbemScripting.SWbemObjectSet
Set objList = GetObject("winmgmts:").ExecQuery("select * from win32_process where name='iexplore.exe'")
此代码返回与所有正在运行的进程“ iexplore.exe”有关的SWbemObjectEx对象的集合
(如在任务管理器中所示)。
我在网上阅读了可以运行该方法的方法。终止这些对象可将其杀死。
但是,在中断模式下的“本地”窗口,“ SWbemObjectEx”类的对象浏览器以及https://docs.microsoft.com/it-ch/windows/win32/wmisdk/swbemobjectex上的官方文档都没有显示此方法终止。
而且令我惊讶的是,尽管并非对所有对象都有效,但它仍然有效……
为什么呢?以及如何查看此类的所有这些hidden(?)方法?
该.Terminate方法是的一部分Win32_Process类。放置一个断点Call objProcess.Terminate
并添加一个手表objProcess
。这将向您显示一个.Methods_
集合,其中第二项是.Terminate
。
还要注意.Properties_
集合以获取有关该进程的信息(例如,句柄)。
此子程序将集合打印到立即窗口,只需在循环中通过调用它objProcesses
,例如
...
For Each objProcess In objProcesses
PrintPropertiesAndMethods objProcess
...
Private Sub PrintPropertiesAndMethods(Process As WbemScripting.SWbemObjectEx)
With Process
Debug.Print vbCrLf & "Properties_ collection:"
Dim Prop As WbemScripting.SWbemProperty
For Each Prop In .Properties_
With Prop
Debug.Print .Name & " " & .Value
End With
Next
Debug.Print vbCrLf & "Methods_ collection:"
Dim Method As WbemScripting.SWbemMethod
For Each Method In .Methods_
With Prop
Debug.Print Method.Name
End With
Next
End With
End Sub
您必须小心终止,iexploror.exe
因为它具有一个主进程(x64-C:\ Program Files \ Internet Explorer),该进程为每个选项卡创建一个子进程(x86-C:\ Program Files(x86)\ Internet Explorer)(签入任务管理器)。如果终止主进程,所有子进程也将终止。无法获得第二个主要测试流程,请使用Run as Admin
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句