どうすればそれができますか?
私はタイマーと一連のプロセスを使用したくありません(これは私が常に行っていた初心者の方法であるため)、より良い改善されたものを探しています。
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