我想获取 WINWORD 进程的所有实例。如图所示,我在 WINWORD 进程中运行了两个窗口。我想获取他们的文件名和路径。
这是我的代码
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(EventArrivedEventArgs, e)
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") & vbNewLine & vbNewLine)
End Sub
Private Sub processStopEvent_EventArrived(EventArrivedEventArgs, e)
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)
FileIO.WriteToFile(" | Date & Time: ")
FileIO.WriteToFile(System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") & vbNewLine & vbNewLine)
End Sub
我正在获取进程名称、ID 以及进程的日期和时间。我想获取进程的实例。