1087 lines
45 KiB
C++
1087 lines
45 KiB
C++
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// BVTUtil.CPP
|
|
//
|
|
//
|
|
// Copyright (c)2000 Microsoft Corporation, All Rights Reserved
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#include "bvt.h"
|
|
#include <time.h>
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int CoCreateInstanceAndLogErrors( REFCLSID clsid, REFIID iid, void ** pPtr,
|
|
BOOL fExpectedFailure, const char * csFile, const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = CoCreateInstance( clsid, NULL, CLSCTX_INPROC_SERVER, iid, (void**) pPtr );
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"CoCreateInstance failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from CoCreateInstance was: 0x%x", hr );
|
|
LogCLSID(csFile,Line, L"REFIID ",iid);
|
|
LogCLSID(csFile,Line, L"REFCLSID ",clsid);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ConnectServerAndLogErrors(IWbemLocator * pLocator, IWbemServices ** pNamespace,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile, const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = pLocator->ConnectServer( CBSTR(wcsNamespace), // NameSpace Name
|
|
NULL, // UserName
|
|
NULL, // Password
|
|
NULL, // Locale
|
|
0L, // Security Flags
|
|
NULL, // Authority
|
|
NULL, // Wbem Context
|
|
pNamespace // Namespace
|
|
);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ConnectServer via IWbemLocator failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ConnectServer was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to open namespace: %s",wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int OpenObjectAndLogErrors( IWbemConnection * pConnection, REFIID iid, void ** pObj,
|
|
WCHAR * wcsObjectName, BOOL fExpectedFailure, const char * csFile, const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the requested object
|
|
// =================================================================
|
|
HRESULT hr = pConnection->Open( CBSTR(wcsObjectName), NULL, NULL, NULL, 0L, NULL, iid,(void**) &pObj, NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Open via IWbemConnection failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Open was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Object Name: %s",wcsObjectName);
|
|
LogCLSID(csFile,Line, L"REFIID",iid);
|
|
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int OpenObjectAsyncAndLogErrors( IWbemConnection * pConnection, REFIID iid, WCHAR * wcsObjectName, IWbemObjectSinkEx * pHandler,
|
|
BOOL fExpectedFailure, const char * csFile, const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the requested object
|
|
// =================================================================
|
|
HRESULT hr = pConnection->OpenAsync(CBSTR(wcsObjectName), NULL, NULL, NULL, 0L, NULL, iid,pHandler);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"OpenAsync via IWbemConnection failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from OpenAsync was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Object Name: %s",wcsObjectName);
|
|
LogCLSID(csFile,Line, L"REFIID",iid);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int GetPropertyAndLogErrors( IWbemClassObject * pClass, WCHAR * wcsProperty, VARIANT * vProperty, CIMTYPE * pType,
|
|
LONG * plFlavor, WCHAR * wcsClassName, WCHAR * wcsNamespace,
|
|
BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = pClass->Get(CBSTR(wcsProperty),0L,vProperty,pType, plFlavor);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Get failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Get was: 0x%x", hr );
|
|
if( wcsClassName )
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get property %s from class: %s from Namespace %s",wcsProperty, wcsClassName,wcsNamespace);
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the class name (property %s) from Namespace %s",wcsProperty, wcsNamespace);
|
|
}
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int GetClassObjectAndLogErrors( IWbemServices * pNamespace, const WCHAR * wcsClassName, IWbemClassObject ** ppClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
WCHAR * wcsClass = (WCHAR*) wcsClassName;
|
|
|
|
HRESULT hr = pNamespace->GetObject(CBSTR(wcsClass),WBEM_FLAG_RETURN_WBEM_COMPLETE,NULL,ppClass,NULL );
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"GetObject failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from GetObject was: 0x%x", hr );
|
|
if( wcsClassName )
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get class: %s from Namespace %s",wcsClassName,wcsNamespace);
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting create an empty class in the Namespace %s",wcsNamespace);
|
|
}
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int SpawnInstanceAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsClassName, IWbemClassObject ** ppInst,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = pClass->SpawnInstance(0, ppInst);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"SpawnInstance failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from SpawnInstance was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to spawn instance of class: %s from Namespace %s",wcsClassName,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int SpawnDerivedClassAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsClassName, IWbemClassObject ** ppInst,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = pClass->SpawnDerivedClass(0, ppInst);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"SpawnDerivedClass failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from SpawnDerivedClass was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to spawn derviced class: %s from Namespace %s",wcsClassName,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutPropertyAndLogErrors( IWbemClassObject * pInst, const WCHAR * wcsProperty, long lType, VARIANT * pVar, const WCHAR * wcsClass,
|
|
DWORD dwFlags,WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
WCHAR * wcsProp = (WCHAR*)wcsProperty;
|
|
HRESULT hr = pInst->Put(CBSTR(wcsProp), dwFlags, pVar, lType);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Put failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Put was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put %s in class %s in Namespace %s",wcsProperty,wcsClass,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutInstanceAndLogErrors( IWbemServices * pNamespace, IWbemClassObject * pInst, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Open the namespace with IWbemServices
|
|
// =================================================================
|
|
HRESULT hr = pNamespace->PutInstance(pInst,WBEM_FLAG_CREATE_OR_UPDATE, NULL, NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"PutInstance failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from PutInstance was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put instance of class %s in Namespace %s",wcsClass,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ClassInheritsFromAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsClass, const WCHAR * wcsParent,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = pClass->InheritsFrom( wcsParent );
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"InheritsFrom failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from InheritsFrom was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to inherit class %s from class %s in Namespace %s",wcsClass,wcsParent,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int GetPropertyQualifierSetAndLogErrors( IWbemClassObject * pClass, IWbemQualifierSet ** pQualifierSet,const WCHAR * wcsProperty,
|
|
const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
*pQualifierSet = NULL;
|
|
WCHAR * wcsProp = (WCHAR*) wcsProperty;
|
|
|
|
hr = pClass->GetPropertyQualifierSet(CBSTR(wcsProp),pQualifierSet);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"GetPropertyQualifierSet failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from GetPropertyQualifierSet was: 0x%x", hr );
|
|
if( wcsProperty )
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the qualifier set for property %s in class %s from class %s in Namespace %s",wcsProperty,wcsClass,wcsNamespace);
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the qualifier set for class %s from class %s in Namespace %s",wcsClass,wcsNamespace);
|
|
}
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutQualifierOnPropertyAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsProperty, const WCHAR * wcsQualifier,
|
|
VARIANT * Var, const WCHAR * wcsClass, DWORD dwFlags,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
IWbemQualifierSet * pQualifierSet = NULL;
|
|
|
|
nRc = GetPropertyQualifierSetAndLogErrors( pClass, &pQualifierSet,wcsProperty,wcsClass,wcsNamespace,fExpectedFailure,csFile,Line );
|
|
if( nRc == SUCCESS )
|
|
{
|
|
WCHAR * wcsQual = (WCHAR*)wcsQualifier;
|
|
hr = pQualifierSet->Put(CBSTR(wcsQual), Var, dwFlags);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
SAFE_RELEASE_PTR(pQualifierSet);
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"QualifierSet->Put failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Put was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put qualifier %s on property %s in class %s in Namespace %s",wcsQualifier, wcsProperty,wcsClass,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int GetClassQualifierSetAndLogErrors( IWbemClassObject * pClass, IWbemQualifierSet ** pQualifierSet,
|
|
const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
*pQualifierSet = NULL;
|
|
|
|
hr = pClass->GetQualifierSet(pQualifierSet);
|
|
if( FAILED(hr))
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"GetQualifierSet failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from GetQualifierSet was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the qualifier set for class %s in Namespace %s",wcsClass,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutQualifierOnClassAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsQualifier,
|
|
VARIANT * Var, const WCHAR * wcsClass, DWORD dwFlags,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
IWbemQualifierSet * pQualifierSet = NULL;
|
|
|
|
nRc = GetClassQualifierSetAndLogErrors( pClass, &pQualifierSet,wcsClass,wcsNamespace,fExpectedFailure,csFile,Line );
|
|
if( nRc == SUCCESS )
|
|
{
|
|
WCHAR * wcsQual = (WCHAR*)wcsQualifier;
|
|
hr = pQualifierSet->Put(CBSTR(wcsQual), Var, dwFlags);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
SAFE_RELEASE_PTR(pQualifierSet);
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"QualifierSet->Put failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Put was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put qualifier %s on class %s in Namespace %s",wcsQualifier, wcsClass,wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int EnumerateClassesAndLogErrors( IWbemServices * pNamespace, IEnumWbemClassObject ** pEnum, DWORD dwFlags, WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Begin enumerating classes
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
|
|
hr = pNamespace->CreateClassEnum(CBSTR(wcsClass), dwFlags,NULL,pEnum);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"CreateClassEnum failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from CreateClassEnum was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to Enumerate Classes in Namespace %s",wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int EnumeratePropertiesAndLogErrors( IWbemClassObject * pClass, DWORD dwFlags, WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Begin enumerating properties
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
|
|
hr = pClass->BeginEnumeration(dwFlags);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"BeginEnumeration failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from BeginEnumeration was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to Enumerate properties for class %s in Namespace %s",wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int EnumerateInstancesAndLogErrors( IWbemServices * pNamespace, IEnumWbemClassObject ** pEnum, const WCHAR * wcsClassName,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Begin enumerating classes
|
|
// =================================================================
|
|
HRESULT hr = S_OK;
|
|
WCHAR * wcsClass = (WCHAR*)wcsClassName;
|
|
|
|
hr = pNamespace->CreateInstanceEnum(CBSTR(wcsClass), WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,NULL,pEnum);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"CreateInstanceEnum failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from CreateInstanceEnum was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to Enumerate instances of class %s in Namespace %s",wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int NextClassAndLogErrors( IEnumWbemClassObject * pEnum, IWbemClassObject ** pClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Get the next class
|
|
// =================================================================
|
|
|
|
unsigned long u = 0;
|
|
HRESULT hr = pEnum->Next(0,1,pClass,&u);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
else if( hr != S_OK )
|
|
{
|
|
nRc = NO_MORE_DATA;
|
|
}
|
|
if( nRc == FATAL_ERROR )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Next failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Next was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the next Class in Namespace %s",wcsNamespace);
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int NextPropertyAndLogErrors( IWbemClassObject * pClass, BSTR * pstrName, VARIANT * pVar, CIMTYPE * lType,
|
|
LONG * lFlavor, WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Get the next class
|
|
// =================================================================
|
|
|
|
unsigned long u = 0;
|
|
HRESULT hr = pClass->Next(0,pstrName, pVar, lType, lFlavor );
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
else if( hr != S_OK )
|
|
{
|
|
nRc = NO_MORE_DATA;
|
|
}
|
|
if( nRc == FATAL_ERROR )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Next failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Next was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the next property for class %s in Namespace %s", wcsClass, wcsNamespace);
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int DeleteClassAndLogErrors(IWbemServices * pNamespace, const WCHAR * wcsClassName,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Delete the class
|
|
// =================================================================
|
|
|
|
WCHAR * wcsClass = (WCHAR*)wcsClassName;
|
|
|
|
HRESULT hr = pNamespace->DeleteClass(CBSTR(wcsClass),0,NULL,NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Delete failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from Delete was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to delete Class %s in Namespace %s",wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int DeleteInstanceAndLogErrors(IWbemServices * pNamespace, const WCHAR * wcsInstanceName,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Delete the requested instance
|
|
// =================================================================
|
|
WCHAR * wcsInstance = (WCHAR*)wcsInstanceName;
|
|
|
|
HRESULT hr = pNamespace->DeleteInstance(CBSTR(wcsInstance),0,NULL,NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"DeleteInstance failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from DeleteInstance was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to delete instance %s in Namespace %s",wcsInstance, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutClassAndLogErrors(IWbemServices * pNamespace, IWbemClassObject * pClass, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set who the class inherits from
|
|
// =================================================================
|
|
HRESULT hr = pNamespace->PutClass(pClass,0,NULL,NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure && ( hr == WBEM_E_CLASS_HAS_CHILDREN ))
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"PutClass failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from PutClass was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put class %s in Namespace %s",wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ExecQueryAndLogErrors(IWbemServices * pNamespace, IEnumWbemClassObject ** ppEnum, WCHAR * wcsQuery, DWORD dwFlags,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Execute the query
|
|
// =================================================================
|
|
|
|
HRESULT hr = pNamespace->ExecQuery(CBSTR(L"WQL"), CBSTR(wcsQuery),dwFlags,NULL,ppEnum);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ExecQuery failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ExecQuery was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to query %s in Namespace %s",wcsQuery, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ExecNotificationQueryAndLogErrors(IWbemServices * pNamespace, IEnumWbemClassObject ** ppEnum, const WCHAR * wcsQuery,
|
|
const WCHAR * wcsLanguage, WCHAR * wcsNamespace, IWbemContext * pCtx,
|
|
BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Execute the notification query
|
|
// =================================================================
|
|
WCHAR * wcsL = (WCHAR*)wcsLanguage;
|
|
WCHAR * wcsQ = (WCHAR*)wcsQuery;
|
|
HRESULT hr = pNamespace->ExecNotificationQuery(CBSTR(wcsL),CBSTR(wcsQ),WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,pCtx,ppEnum);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ExecNotificationQuery failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ExecNotificationQuery was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to query %s in Namespace %s using Language %s",wcsQuery, wcsNamespace, wcsLanguage);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ExecNotificationQueryAsyncAndLogErrors(IWbemServices * pNamespace, CSinkEx * pResponse, const WCHAR * wcsQuery,
|
|
const WCHAR * wcsLanguage, WCHAR * wcsNamespace, IWbemContext * pCtx,
|
|
BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Execute the notification query
|
|
// =================================================================
|
|
WCHAR * wcsL = (WCHAR*)wcsLanguage;
|
|
WCHAR * wcsQ = (WCHAR*)wcsQuery;
|
|
|
|
HRESULT hr = pNamespace->ExecNotificationQueryAsync(CBSTR(wcsL),CBSTR(wcsQ),0,pCtx,pResponse);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ExecNotificationQueryAsync failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ExecNotificationQueryAsync was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to query %s in Namespace %s using Language %s",wcsQuery, wcsNamespace, wcsLanguage);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int CancelAsyncCallAndLogErrors(IWbemServices * pNamespace, CSinkEx * pResponse, const WCHAR * wcsQuery,
|
|
const WCHAR * wcsLanguage, WCHAR * wcsNamespace,
|
|
BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Cancel the notification query
|
|
// =================================================================
|
|
|
|
HRESULT hr = pNamespace->CancelAsyncCall(pResponse);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"CancelAsyncCall failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from CancelAsyncCall was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to cancel handler for query %s in Namespace %s using Language %s",wcsQuery, wcsNamespace, wcsLanguage);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int PutMethodAndLogErrors( IWbemClassObject * pClass, IWbemClassObject * pInClass,
|
|
IWbemClassObject * pOutClass,const WCHAR * wcsMethodName, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Set the method
|
|
// =================================================================
|
|
HRESULT hr = pClass->PutMethod(wcsMethodName,0,pInClass,pOutClass);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"PutMethod failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from PutMethod was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to put method %s on class %s in Namespace %s",wcsMethodName, wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int DeleteMethodAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsMethodName, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Delete the method
|
|
// =================================================================
|
|
HRESULT hr = pClass->DeleteMethod(wcsMethodName);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"DeleteMethod failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from DeleteMethod was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to delete method %s on class %s in Namespace %s",wcsMethodName, wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int EnumerateMethodAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Delete the method
|
|
// =================================================================
|
|
HRESULT hr = pClass->BeginMethodEnumeration(0);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"BeginMethodEnumeration failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from BeginMethodEnumeration was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to enumerate methods on class %s in Namespace %s", wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int NextMethodAndLogErrors( IWbemClassObject * pClass, const WCHAR * wcsClass, BSTR * pName, IWbemClassObject ** ppIn,
|
|
IWbemClassObject ** ppOut,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Delete the method
|
|
// =================================================================
|
|
HRESULT hr = pClass->NextMethod(0,pName,ppIn,ppOut);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
else if( hr != S_OK )
|
|
{
|
|
nRc = NO_MORE_DATA;
|
|
}
|
|
if( nRc == FATAL_ERROR )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = FAILED_AS_EXPECTED;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"NextMethod failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from NextMethod was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to get the next method for class %s in Namespace %s", wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ExecuteMethodAndLogErrors(IWbemServices * pNamespace,
|
|
WCHAR * wcsMethod, WCHAR * wcsPath,
|
|
long lFlags,
|
|
IWbemClassObject *pIn,
|
|
IWbemClassObject **ppOut,
|
|
const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Execute the method
|
|
// =================================================================
|
|
HRESULT hr = pNamespace->ExecMethod(CBSTR(wcsPath),CBSTR(wcsMethod), lFlags, NULL, pIn, ppOut,NULL);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ExecMethod failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ExecMethod was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to execute the method %s for class %s in Namespace %s", wcsMethod,wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int ExecMethodAsyncAndLogErrors(IWbemServices * pNamespace, WCHAR * wcsMethod, WCHAR * wcsPath,
|
|
long lFlags,
|
|
IWbemClassObject *pIn,
|
|
IWbemObjectSink *pResponseHandler,
|
|
const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Execute the method
|
|
// =================================================================
|
|
HRESULT hr = pNamespace->ExecMethodAsync(CBSTR(wcsPath),CBSTR(wcsMethod), lFlags, NULL, pIn, pResponseHandler);
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"ExecMethodAsync failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from ExecMethodAsync was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to execute the method async %s for class %s in Namespace %s", wcsMethod,wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int GetMethodAndLogErrors(IWbemClassObject * pClass, WCHAR * wcsMethod, IWbemClassObject **ppIn,
|
|
IWbemClassObject **ppOut, const WCHAR * wcsClass,
|
|
WCHAR * wcsNamespace, BOOL fExpectedFailure, const char * csFile , const ULONG Line )
|
|
{
|
|
int nRc = SUCCESS;
|
|
// =================================================================
|
|
// Get the method
|
|
// =================================================================
|
|
HRESULT hr = pClass->GetMethod(wcsMethod,0, ppIn, ppOut );
|
|
if( FAILED(hr))
|
|
{
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
if( nRc != SUCCESS )
|
|
{
|
|
if( fExpectedFailure )
|
|
{
|
|
nRc = SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"GetMethod failed." );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"HRESULT from GetMethod was: 0x%x", hr );
|
|
gp_LogFile->LogError(csFile,Line,FATAL_ERROR, L"Attempting to Get the method %s for class %s in Namespace %s", wcsMethod,wcsClass, wcsNamespace);
|
|
nRc = FATAL_ERROR;
|
|
}
|
|
}
|
|
return nRc;
|
|
}
|
|
|
|
|
|
|