CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    221

    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

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  3. #3
    Join Date
    Apr 2005
    Posts
    221

    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.

  4. #4
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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
  •  





Click Here to Expand Forum to Full Width

Featured