我可以从 System.Management.EventArrivedEventArgs 对象获取 ExecutablePath 吗?
我正在使用 System.Management.ManagementEventWatcher 来获取已启动进程的进程 ID 和可执行路径:
private void startWatcher_EventArrived(Object sender, EventArrivedEventArgs e)
{
String processID = e.NewEvent.Properties["ProcessID"].Value.ToString();
var searcher = new ManagementObjectSearcher(new WqlObjectQuery(String.Format("Select ExecutablePath from Win32_Process where ProcessID = {0}", processID)));
ManagementObject managementObject = null;
foreach (ManagementObject obj in searcher.Get())
{
managementObject = obj;
break;
}
Console.WriteLine(managementObject["ExecutablePath"]);
}
使用此 WQL 查询:
从中选择可执行路径 Win32_ProcessStartTrace
有没有一种方法可以避免进行对象搜索,但仍然使用 EventArrivedEventArgs 对象中已有的内容来获取 ExecutionPath?
我真正需要的是每个启动的新进程的 ProcessID 和 ExecuatblePath。这是最简单的方法吗?
I'm using a System.Management.ManagementEventWatcher to get the process ID and executable path for a started process:
private void startWatcher_EventArrived(Object sender, EventArrivedEventArgs e)
{
String processID = e.NewEvent.Properties["ProcessID"].Value.ToString();
var searcher = new ManagementObjectSearcher(new WqlObjectQuery(String.Format("Select ExecutablePath from Win32_Process where ProcessID = {0}", processID)));
ManagementObject managementObject = null;
foreach (ManagementObject obj in searcher.Get())
{
managementObject = obj;
break;
}
Console.WriteLine(managementObject["ExecutablePath"]);
}
Using this WQL Query:
Select ExecutablePath from
Win32_ProcessStartTrace
Is there a way that I can avoid doing the object search, but still get the ExecutionPath, using what is already available in the EventArrivedEventArgs object?
All I really need is the ProcessID and the ExecuatblePath for each new process that starts up. Is this the simplest way to get that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你得到的已经是最好的了。 此处列出了可用属性...
No, what you got is as good as it gets. The available properties are listed here...
我相信这篇文章可以帮助您: 使用 WMI 监视进程创建.NET中的删除和修改
I believe this article can help you: Using WMI to monitor process creation, deletion and modification in .NET