'检测指定进程是否运行
Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckApplicationIsRun = False
WMI = GetObject("WinMgmts:")
Objs = WMI.InstancesOf("Win32_Process")
For Each Obj In Objs
If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
CheckApplicationIsRun = True
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
Exit Function
End If
Next
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
Exit Function
Err:
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
End Function
========================================
窗体按钮点击的事件:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (CheckApplicationIsRun("123.exe")) Then '123.exe为判断的程序名,修改即可
MessageBox.Show("已经运行")
Else
MessageBox.Show("没有运行")
End If
End Sub