SOL9 2.0 Class: WbemLocator

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * WbemLocator.h 
 * Copyright (c) 2012 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// 2010/03/14
// 2012/03/08 Updated

#pragma once

#include <sol/com/ComIUnknown.h>
#include <objbase.h>

#include <sol/COMTypeConverter.h>
#include <sol/Writer.h>
#include <sol/FileWriter.h>
#include <sol/ConsoleWriter.h>

#include <sol/LocalDateTime.h>
#include <sol/HTMLEncoder.h>

#pragma comment(lib, "oleaut32.lib")

#include <sol/wmi/WbemServices.h>

namespace SOL {

class WbemLocator : public ComIUnknown {

public:
    WbemLocator()
    :ComIUnknown()
    {
        HRESULT hr = S_OK;
        IDispatch* pDisp = NULL;
        // Create an initial locator to WbemLocator 
        if (FAILED(hr = CoCreateInstance(
                CLSID_WbemLocator,             
                0, 
                CLSCTX_INPROC_SERVER, 
                IID_IWbemLocator, (void**) &pDisp)) ) {

                throw Exception(E_FAIL, "%s: %s", "E_FAIL",__FUNCTION__);
        } else {
            set(pDisp);        
        }
    }

public:
    ~WbemLocator () 
    {
    }

public:
    IWbemLocator* getLocator()
    {
        return (IWbemLocator*)getIUnknown();
    }

public:
    IWbemServices*  connectServer( 
        __in const BSTR strNetworkResource,
        __in const BSTR strUser=NULL,
            __in const BSTR strPassword=NULL,
            __in const BSTR strLocale=NULL,
            __in long lSecurityFlags=NULL,
            __in const BSTR strAuthority=NULL,
            __in IWbemContext *pCtx=NULL)
    {
        HRESULT hr = S_OK;
        IWbemServices *pServices =NULL;
        IWbemLocator* locator = getLocator();
        if (FAILED(hr = locator -> ConnectServer( 
            strNetworkResource,
            strUser,
            strPassword,
            strLocale,
            lSecurityFlags,
            strAuthority,
            pCtx,
            &pServices) )) {
            throw Exception(E_FAIL, "%s: %s", "E_FAIL",__FUNCTION__);
        }
        else {
            return pServices;
        }
    }    


};

}

Last modified: 1 Apr 2012

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