🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
1 messages
1 total messages Started by JohnG Tue, 15 Jan 2008 19:55
__InstanceModificationEvent & TargetInstance
#715
Author: JohnG
Date: Tue, 15 Jan 2008 19:55
80 lines
3065 bytes
Hello,

The code (partial snippet) monitors a wmi event. Looking for
changes to Win32_NetworkAdapter class. The code successfully
detects changes to the the NetworkAdapter, however I cannot access any of the Win32_NetworkAdapter properties. When I call
GetObjectText() method of IWbemClassObject object I see the properties I wish to access under 'TargetInstance'. Is there any way (short of text parsing) to access 'TargetInstance' as an object.




HRESULT hr;

TComInterface< IWbemLocator > locator;
hr = CoCreateInstance( CLSID_WbemLocator, NULL,
                       CLSCTX_INPROC_SERVER,
		       IID_IWbemLocator, reinterpret_cast< void** >( &locator ) );
	
if ( FAILED( hr ) )
{
   ShowMessage("Instantiation of IWbemLocator failed");
   return;
}

// connect to local service with current credentials
TComInterface< IWbemServices > service;

hr = locator->ConnectServer( WideString("root\\cimv2"), NULL, 
                             NULL, NULL,
			     WBEM_FLAG_CONNECT_USE_MAX_WAIT,
			     NULL, NULL, &service );

if ( SUCCEEDED( hr ) )
{
   IEnumWbemClassObject* pEnumerator = NULL;
   
   hr = service->ExecNotificationQuery(
	WideString("WQL"),
	WideString("select * from __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_NetworkAdapter' And TargetInstance.Description = \"Intel(R) PRO/1000 MT Network Connection\""),
	WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
	NULL, &pEnumerator);

  if (hr == WBEM_E_NOT_EVENT_CLASS)
  {
     ShowMessage("Not Valid Event class");
     return;
  }

  if (FAILED(hr))
  {
    ShowMessage("Query Failed");
    return;
  }

  IWbemClassObject *pclsObj;
  ULONG uReturn = 0;

  while (pEnumerator) 
  {
     HRESULT hr = pEnumerator->Next(5000,
                                    1,
                                    &pclsObj,
                                     &uReturn);

   if(hr == WBEM_S_TIMEDOUT)
   {
     Application->ProcessMessages();
     continue;
   }

   if(0 == uReturn)
     break;

   WideString   tmp;
   VARIANT vtProp;
   pclsObj->GetObjectText(0,&tmp);

   ShowMessage(tmp);
 }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads