您可以使用ManagementObjectSearcher
获取进程的命令行参数,在这个记事本示例中,您可以解析出文件名。这是一个简单的控制台应用程序示例,它在记事本中写出所有打开文件的完整路径和文件名。
Imports System
Imports System.ComponentModel
Imports System.Management
Module Module1
Sub Main()
Dim cl() As String
For Each p As Process In Process.GetProcessesByName("notepad")
Try
Using searcher As New ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " & p.Id)
For Each mgmtObj As ManagementObject In searcher.Get()
cl = mgmtObj.Item("CommandLine").ToString().Split("""")
Console.WriteLine(cl(cl.Length - 1))
Next
End Using
Catch ex As Win32Exception
'handle error
End Try
Next
System.Threading.Thread.Sleep(1000000)
End Sub
End Module
我必须添加对这个特定 dll 的引用:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Managment.dll