Management Event Watcher can do what exactly you are looking. Have a look: ManagementEventWatcher.Stop Method
Monitoring the execution of all process
-
03-04-2022 - |
문제
How I can do it?
I don't want to use a timer + an array of processes (because that's the newbie way that I allways did) I'm looking for something better and improved.
I've tried using ManagementEventWatcher but this code example is not working in Windows 7 (I don't get any error, but is not showing the 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
해결책
다른 팁
This will get the name and PID of each running process, simply modify this code to get any additional information...
Dim processList As String
For Each p As Process In Process.GetProcesses()
processList = processList & " " & p.SessionId & vbNewLine
Next()
MsgBox(processList)
제휴하지 않습니다 StackOverflow