编程语言
首页 > 编程语言> > 搬家第25天-citectv7.4citectVBA判断某个程序是否在运行,如果在运行就关掉它

搬家第25天-citectv7.4citectVBA判断某个程序是否在运行,如果在运行就关掉它

作者:互联网

比如判断计算器是否在运行,如果在运行就关掉它。

Sub killprocess()
Dim strComputer  As string
Dim objWMIService As Object
Dim colProcessList As Object
Dim i As Object
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'calc.exe'")
If colProcessList.Count>0 Then
   For Each i In colProcessList
     i.terminate
   Next
Else
  msgbox "没运行"
End If
End Sub

标签:25,objWMIService,Sub,ObjectDim,colProcessList,strComputer,citectVBA,citectv7.4,
来源: https://www.cnblogs.com/fishingsriver/p/14429476.html