|
-
September 29th, 2005, 03:01 PM
#1
WMI, watching for multiple events in C#
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
-
September 29th, 2005, 04:51 PM
#2
Re: WMI, watching for multiple events in C#
I'm not sure exactly how this "query language" works, but your where clause seems a bit odd:
Code:
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
What if you try something like:
Code:
SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE (TargetInstance ISA \"Win32_Processor\" AND TargetInstance.Availability=3) OR (TargetInstance ISA \"Win32_NetworkAdapter\" AND TargetInstance.Availability=3)
- petter
-
September 29th, 2005, 05:36 PM
#3
Re: WMI, watching for multiple events in C#
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.
-
September 29th, 2005, 06:27 PM
#4
Re: WMI, watching for multiple events in C#
BTW, what are the code tags to put the code nicely ? Aren't they <code></code>
Replace '<' with '[' and '>' with ']'.
- petter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|