none
ManagementEventWatcher.EventArrived doenot work all the time

    Question

  • Hi

    I am using ManagementEventWatcher to findout when a specific exe is started.

     _startWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
    _startWatch.EventArrived += new EventArrivedEventHandler(startWatch_EventArrived);
                _startWatch.Start();

    The EventArrived event should be fired when an exe is started. But unfortunately this does not work. I do have admin rights on the machine (just thought of mentioning this as some of the posts give this as one of the reasons).

    Regards

    JC

    Wednesday, October 10, 2012 4:14 AM

Answers

  • Hi Jc0616,

    Welcome to the MSDN Forum.

    I also tested a WPF project. it works fine.

    Now, I need to know how you think the event is not fired? 

    I just tried to write a line of current time when the event fired.

            private void watcher_EventArrived(Object sender, EventArrivedEventArgs e)
            {
                Console.WriteLine(e.Context);
                Console.WriteLine(DateTime.Now);
            }

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 12, 2012 8:20 AM

All replies

  • Are you observing any perticular process? Below code definitely fires the EventArrived event when Notepad is opened.

    var wqlQuery = new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace where ProcessName='notepad.exe'");
    var watcher = new ManagementEventWatcher(wqlQuery);
    watcher.EventArrived += watcher_EventArrived;
    watcher.Start();

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Wednesday, October 10, 2012 5:32 AM
  • yes I am observing start of another WPF application, which we have created. Its a simple WPF application.

    And it does work rarely but most of the times the event is not fired.

    Regards

    JC

    Thursday, October 11, 2012 8:18 AM
  • Hi Jc0616,

    Welcome to the MSDN Forum.

    I also tested a WPF project. it works fine.

    Now, I need to know how you think the event is not fired? 

    I just tried to write a line of current time when the event fired.

            private void watcher_EventArrived(Object sender, EventArrivedEventArgs e)
            {
                Console.WriteLine(e.Context);
                Console.WriteLine(DateTime.Now);
            }

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 12, 2012 8:20 AM