监视进程

0 Reply , Posted in 程序代码 on 2016 08, 2016

Private Sub Timer1_Timer()
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
    For Each objprocess In colProcesses
        If objprocess.Name = "QQ.exe" Then MsgBox "QQ正在运行", vbOKOnly, "提示": End
    Next
End Sub
'---------------------------貌似还是这种方法最好,方法二太臃肿
'==============================方法一==============================

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 Command1_Click()
    If CheckApplicationIsRun("QQ.exe") = True Then
        MsgBox "QQ程序已运行"
    Else
        MsgBox "QQ程序没有运行"
    End If
End Sub
'==============================方法二==============================

标签:     

相关推荐

vb读取access并且显示  (2017-5-11 9:18:27)

VB 获取CPU温度示例  (2017-5-8 10:35:11)

VB程序逆向反汇编常见的函数   (2017-5-8 10:32:0)

VB内嵌汇编的模块示例  (2017-5-8 10:24:4)

内存数据的读写(PC)   (2017-3-1 17:51:40)

用VB制作外挂   (2017-3-1 16:16:53)

发表评论:



◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

                       

  鄂公网安备 42112502000156号     鄂ICP备16019550号