定期检测程序运行
本帖最后由 bcrun 于 2012-08-29 09:43:47 编辑
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 3000
End Sub
Private Sub Timer1_Timer()
If 0 = getPID("qq.exe") Then MsgBox "程序已关闭", vbInformation, "提示"
End Sub
Function getPID(qq As String) As Long
Dim objWMIService, objProcess, colProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess In colProcess
If LCase(objProcess.Name) = LCase(qq) Then
getPID = objProcess.ProcessID
Exit For
End If
Next
Set objWMIService = Nothing
Set objProcess = Nothing
End Function