聆听新进程:需要简单的解释

发布于 2024-12-24 02:00:00 字数 515 浏览 0 评论 0原文

只是需要一点解释。

我在此处引用有关监听进程的问题。我还收到评论中提到的“访问被拒绝”错误,但不确定如何以管理员身份运行该示例的 WMI 服务。请有人指出我正确的方向。

这是我到目前为止所拥有的。

startWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
startWatch.EventArrived += new EventArrivedEventHandler(ProcessEvent);
startWatch.Start();

private void ProcessEvent(object sender, EventArrivedEventArgs e)
{...}

just need a little explanation please.

I am referencing question here about listening to processes. I am also getting the "access denied" error as mentioned in the comments but not sure how to run the WMI service as administrator for the example. Someone please point me in the right direction.

Here is what I have so far.

startWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
startWatch.EventArrived += new EventArrivedEventHandler(ProcessEvent);
startWatch.Start();

private void ProcessEvent(object sender, EventArrivedEventArgs e)
{...}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-12-31 02:00:00
ManagementScope theScope = new ManagementScope("\\\\ComputerName\\root\\cimv2");
ObjectQuery theQuery = new ObjectQuery("SELECT * FROM Win32_ProcessStartTrace");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollection = theSearcher.Get();
foreach (ManagementObject theCurObject in theCollection)
{
  MessageBox.Show(theCurObject["whatever properties you are looking for"].ToString());
}
ManagementScope theScope = new ManagementScope("\\\\ComputerName\\root\\cimv2");
ObjectQuery theQuery = new ObjectQuery("SELECT * FROM Win32_ProcessStartTrace");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollection = theSearcher.Get();
foreach (ManagementObject theCurObject in theCollection)
{
  MessageBox.Show(theCurObject["whatever properties you are looking for"].ToString());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文