SOL9 Sample: SWbemProcessOperationNotificationQueryApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SWbemProcessOperationNotificationQueryApplet.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//SOL9
// 2009/12/13

#include <sol/wmi/SWbemNotificationQueryApplet.h>

namespace SOL {

/**
 * Thread of SWbemServices::ExeNotificationQuery to watch __InstandeOperationEvent for Win32_Process 
 */
class SWbemProcessOperationNotificationQueryApplet: public SWbemNotificationQueryApplet {

public:  
  /**
   * Constructor
   */
  SWbemProcessOperationNotificationQueryApplet()
  {
  
  }

public:
  /**
   * Thread procedure to watch an instance opertion event of Win32_Process.
   */
  virtual void display(SWbemEventSource& eventSource)
  {
    bool looping = true;
    while (looping) { 
      try {
        SWbemQueryProperties& properties = getQueryProperties();

        int nextEventInterval = properties.getNextEvent();

        SWbemObject object   = eventSource.nextEvent(nextEventInterval);
  

        SWbemObjectPath path = object.getPath();
            
        _bstr_t strClass = path.getClass();
        //printf("Notified SWbemObject Class=%S\n", (const wchar_t*)strClass);

        
        if (strClass == _bstr_t("__InstanceCreationEvent") ) {
          _bstr_t text = object.getObjectText(0);
          printf("InstanceCreated %S\n", (const wchar_t*)text);
        }
        if (strClass == _bstr_t("__InstanceDeletionEvent") ) {
          _bstr_t text = object.getObjectText(0);
          printf("InstanceDeleted %S\n", (const wchar_t*)text);
        }
      
      } catch (...) {

      }   
    }
  }

};

}

void _tmain(int argc, const TCHAR ** argv)
{
  try {
    SWbemProcessOperationNotificationQueryApplet applet;
    applet.start();

    applet.wait();

  } catch (...) {

  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.