在我的代码中出现异常
Public Class Form1
Dim processStartEvent As ManagementEventWatcher = New ManagementEventWatcher("SELECT * FROM Win32_ProcessStartTrace")
Dim processStopEvent As ManagementEventWatcher = New ManagementEventWatcher("SELECT * FROM Win32_ProcessStopTrace")
Public Sub New()
InitializeComponent()
AddHandler processStartEvent.EventArrived, AddressOf Me.processStartEvent_EventArrived
processStartEvent.Start()
AddHandler processStopEvent.EventArrived, AddressOf Me.processStopEvent_EventArrived
processStopEvent.Start()
End Sub
Private Sub processStartEvent_EventArrived(sender As Object, e As EventArrivedEventArgs)
Dim processName As String = e.NewEvent.Properties("ProcessName").Value.ToString
Dim processID As String = Convert.ToInt32(e.NewEvent.Properties("ProcessID").Value).ToString
FileIO.WriteToFile("+ Process started. Name: " & processName & " | ID: " + processID)
FileIO.WriteToFile(" | Date & Time: ")
FileIO.WriteToFile(System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))
End Sub
Private Sub processStopEvent_EventArrived(sender As Object, e As EventArrivedEventArgs)
Dim processName As String = e.NewEvent.Properties("ProcessName").Value.ToString
Dim processID As String = Convert.ToInt32(e.NewEvent.Properties("ProcessID").Value).ToString
FileIO.WriteToFile("- Process stopped. Name: " & processName & " | ID: " + processID)
End Sub End Class
如何处理管理异常