怎么VB6检测指定进程是否已经存在

来源:百度知道 编辑:UC知道 时间:2024/06/19 23:12:03
RT
在Command1_click()时检测 D:\Program files\abc.exe 是否已经运行
如果运行,N=1,否则N=0
希望用最简短,有效的代码...

On Error Resume Next
Dim s, objWMIService, colProcessList, objProcess
Dim mFind As Boolean
s="abc.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
Next
If mFind Then '如果找到
n=1
Else '如果找不到
n=0
End If