'检测指定的进程是否存在
On Error Resume Next
Dim s As String, mFind As Boolean
Dim objWMIService, colProcessList, objProcess
s = "cmd.exe"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & s & "'")
For Each objProcess In colProcessList
mFind = True '检测到则标识为真
objProcess.Terminate
Next
If mFind = False Then
MsgBox "不存在!", vbInformation, "提示"
else
MsgBox "存在!", vbInformation, "提示"
End If
Set objProcess = Nothing
Set colProcessList = Nothing
Set objWMIService = Nothing