天天看點

VB監控程式運作

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

'監控某一程式

繼續閱讀