vb中如何监视系统进程

来源:百度知道 编辑:UC知道 时间:2024/06/08 21:34:54
比如 新建一个按钮 功能为 :
------------------------------------------------
检测"abc.exe"进程
检测到"abc.exe"进程
则 msgbox "有 abc.exe 进程存在"
没有检测到"abc.exe"进程
则 msgbox "没有 abc.exe 进程存在"
------------------------------------------------
请问怎么写呢?
我是菜鸟 请大虾们尽量详细哈 嘿嘿 ....

Private Sub Command1_Click()
s = "abc.exe"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & s & "'")

b = False
For Each objProcess In colProcessList
b = True
Exit For
Next

If b Then
MsgBox "有 " & s & " 进程存在"
Else
MsgBox "没有 " & s & " 进程存在"
End If
End Sub