请稍微解释一下。
我正在引用有关收听流程的问题here。我也收到了评论中提到的“访问被拒绝”错误,但不知道如何以管理员身份运行WMI服务。有人请指出我正确的方向。
这是我到目前为止所拥有的。
startWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
startWatch.EventArrived += new EventArrivedEventHandler(ProcessEvent);
startWatch.Start();
private void ProcessEvent(object sender, EventArrivedEventArgs e)
{...}
答案 0 :(得分:1)
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());
}