0

在我的代码中出现异常

如图所示,如何处理此异常

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

如何处理管理异常

4

1 回答 1

0

您会得到该异常,因为程序正在运行的用户无权从该文件夹读取或执行程序。

在不告诉我们您尝试执行什么以及它存储在哪里的情况下,这就是我们可以告诉您的全部内容。

于 2019-11-22T05:17:28.937 回答