VB监控程序运行

来源:互联网 发布:歼20骗局知乎 编辑:程序博客网 时间:2024/04/28 07:25

Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
      On Error GoTo Err
      Dim WMI
      Dim Obj
      Dim Objs
      CheckApplicationIsRun = False
      Set WMI = GetObject("WinMgmts:")
      Set 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 Set Objs = Nothing
                     If Not WMI Is Nothing Then Set WMI = Nothing
                     Exit Function
               End If
      Next
      If Not Objs Is Nothing Then Set Objs = Nothing
      If Not WMI Is Nothing Then Set WMI = Nothing
      Exit Function
Err:
      If Not Objs Is Nothing Then Set Objs = Nothing
      If Not WMI Is Nothing Then Set WMI = Nothing
   End Function

 

Private Sub Timer1_Timer()
    If CheckApplicationIsRun("QQ.exe") = True Then
        Print "程序已在运行"
    Else
        Print "程序没有在运行"
    End If

End Sub

'监控某一程序

原创粉丝点击