有时候我们需要判断某个程序是否已经运行,使用citectvba脚本可以实现这个功能,下面的代码实验判断计算器程序是否运行,通过进程查找calc.exe是否存在来判断。
Sub FindProcess()
Dim strComputer As string
Dim objWMIService As Object
Dim colProcessList 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
msgbox "运行"
Else
msgbox "没运行"
End If
End Sub