Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Management
- Public Class Form1
- Dim WithEvents ProcessStartWatcher As New ManagementEventWatcher(New WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"))
- Dim WithEvents ProcessStopWatcher As New ManagementEventWatcher(New WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"))
- Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
- ProcessStartWatcher.Start()
- ProcessStopWatcher.Start()
- End Sub
- Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs)
- ProcessStartWatcher.Stop()
- ProcessStopWatcher.Stop()
- End Sub
- Private Sub ProcessStartWatcher_EventArrived(sender As Object, e As System.Management.EventArrivedEventArgs) Handles ProcessStartWatcher.EventArrived
- Dim ProcessName As String = e.NewEvent.Properties("ProcessName").Value
- Dim PID As Integer = e.NewEvent.Properties["ID"].Value
- MessageBox.Show(String.Format("Process ""{0}"" with ID {1} started.", ProcessName, PID))
- End Sub
- Private Sub ProcessStopWatcher_EventArrived(sender As Object, e As System.Management.EventArrivedEventArgs) Handles ProcessStopWatcher.EventArrived
- Dim ProcessName As String = e.NewEvent.Properties("ProcessName").Value
- Dim PID As Integer = e.NewEvent.Properties["ID"].Value
- MessageBox.Show(String.Format("Process ""{0}"" with ID {1} stopped.", ProcessName, PID))
- End Sub
- End Class
Add Comment
Please, Sign In to add comment