Click to See Complete Forum and Search --> : WMI, watching for multiple events in C#


novice123
September 29th, 2005, 03:01 PM
Hi,

I have question regarding watching multiple events using ManagementEventwatcher in C#.

Following is the code
<code>
string eventquery = "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA \"Win32_Processor\" AND TargetInstance.Availability=3";

MyEventAsyncHandler handler = new MyEventAsyncHandler();

ManagementEventWatcher watcher = new ManagementEventWatcher(eventquery);
watcher.EventArrived += new EventArrivedEventHandler(handler.EventArrived);
watcher.Stopped += new StoppedEventHandler(handler.StoppedEvent);
watcher.Start();
</code>

Here in the event query, i can only watch for event modification of Win32_Processor. Is there a way to watch for multiple events , i.e can i watch for events of Win32_Processor, Win32_NetworkAdapter, Win32_Processor

I tried the query below, but it throws unparseable error at run time
</code>
//string eventquery = "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE WHERE TargetInstance ISA \"Win32_Processor\" AND TargetInstance.Availability=3 OR WHERE TargetInstance ISA \"Win32_NetworkAdapter\" AND TargetInstance.Availability=3 ";
<code>

If someone has done this before, please let me know

TIA

wildfrog
September 29th, 2005, 04:51 PM
I'm not sure exactly how this "query language" works, but your where clause seems a bit odd:

SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE WHERE TargetInstance ISA \"Win32_Processor\" AND TargetInstance.Availability=3 OR WHERE TargetInstance ISA \"Win32_NetworkAdapter\" AND TargetInstance.Availability=3What if you try something like:

SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE (TargetInstance ISA \"Win32_Processor\" AND TargetInstance.Availability=3) OR (TargetInstance ISA \"Win32_NetworkAdapter\" AND TargetInstance.Availability=3)

- petter

novice123
September 29th, 2005, 05:36 PM
Wildfrog,

Thanks !. My bad i should have checked twice.

Atleast, it does not throw unparsable error.

BTW, what are the code tags to put the code nicely ? Aren't they <code></code>

I tried them, but did not work.

Thanks a lot for your help.

wildfrog
September 29th, 2005, 06:27 PM
BTW, what are the code tags to put the code nicely ? Aren't they <code></code>
Replace '<' with '[' and '>' with ']'.

- petter