Hi, I have the following code:
WqlEventQuery query = new WqlEventQuery();
query.EventClassName = "__InstanceOperationEvent";
query.WithinInterval = new TimeSpan(0, 0, 1);
query.Condition = "TargetInstance ISA \"Win32_Service\" AND
TargetInstance.Name = \"CentennialClientAgent\"";
watcher = new ManagementEventWatcher(query);
watcher.EventArrived += new EventArrivedEventHandler(this.Arrived);
watcher.Start();
private void Arrived(object sender, EventArrivedEventArgs e) {
ManagementBaseObject o =
(ManagementBaseObject)e.NewEvent["TargetInstance"];
System.Diagnostics.Debug.WriteLine(o["Started"].ToString());
System.Diagnostics.Debug.WriteLine(o["StartMode"].ToString());
//TODO: how do I get the instance and invoke the method - such as
StopService()
}
My question is how can I get the ManagementObject from the
ManagementBaseObject? because what I wanted to do is to invoke a method on
that instance - only ManagementObject has invokemethod.
Thanks!
John