我該怎麼做?我不想使用一個定時器+一個進程數組(因爲這是我總是做的新手),我正在尋找更好的東西和改進。監控所有進程的執行情況
我使用ManagementEventWatcher但是這個代碼示例試過沒有在Windows 7中工作(我沒有得到任何錯誤,但不顯示MsgBoxes):
Public Class Form1
Dim WithEvents startWatch As New System.Management.ManagementEventWatcher(New System.Management.WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"))
Dim WithEvents stopWatch As New System.Management.ManagementEventWatcher(New System.Management.WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler startWatch.EventArrived, AddressOf startWatch_EventArrived
AddHandler stopWatch.EventArrived, AddressOf stopWatch_EventArrived
startWatch.Start()
stopWatch.Start()
End Sub
Public Sub startWatch_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs)
MsgBox("Process started: " & e.NewEvent.Properties("ProcessName").Value)
End Sub
Private Sub stopWatch_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArrivedEventArgs)
MsgBox("Process stopped: " & e.NewEvent.Properties("ProcessName").Value)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
startWatch.Stop()
stopWatch.Stop()
End Sub
End Class
請嘗試閱讀此http://stackoverflow.com/help/deleted-answers,以獲得更多的理解如何**不**回答。即:「不能從根本上回答問題的答案」:**僅僅是一個鏈接到外部網站** –