日期:2014-05-16 浏览次数:20930 次
static void Main(string[] args)
{
ManagementScope scope = new System.Management.ManagementScope(@"\\.\root\CIMV2");
WqlEventQuery query = new WqlEventQuery(
"__InstanceCreationEvent",
new TimeSpan(0, 0, 1),
"TargetInstance isa \"Win32_Process\"");
ManagementEventWatcher watcher = new ManagementEventWatcher(scope, query);
watcher.EventArrived += (s, e) => {
Console.WriteLine("Process {0} has been created.",
((ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value).Properties["Name"].Value.ToString());
};
watcher.Start();
Console.ReadKey();
}