SOL9 2.0 Sample: SWbemProcessOperationNotificationQueryApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SWbemProcessOperationNotificationQueryApplet.cpp 
 * Copyright (c) 2009 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)
    {

        while (true) { 
            try {
                SWbemQueryProperties& properties = getQueryProperties();

                int nextEventInterval = properties.getNextEvent();

                SWbemObject object   = eventSource.nextEvent(nextEventInterval);
    

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

                
                if (strClass == L"__InstanceCreationEvent") {
                    BString text = object.getObjectText(0);
                    printf("InstanceCreated %S\n", (const wchar_t*)text);
                }
                if (strClass == L"__InstanceDeletionEvent") {
                    BString 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: 24 Dec 2009

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