Article View: borland.public.cppbuilder.nativeapi
Article #715__InstanceModificationEvent & TargetInstance
From: JohnG
Date: Tue, 15 Jan 2008 19:55
Date: Tue, 15 Jan 2008 19:55
80 lines
3065 bytes
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);
}
}
Technical Details
Message-ID:
<478d1dae$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,adc802d91248792e,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "JohnG" <whatis@email.com> Sender: "JohnG" <whatis@email.com> Reply-To: "JohnG" <whatis@email.com> Subject: __InstanceModificationEvent & TargetInstance Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 138.11.0.153 X-Forwarded-For: unknown NNTP-Posting-Host: 207.105.83.66 Message-ID: <478d1dae$1@newsgroups.borland.com> Date: 15 Jan 2008 12:55:10 -0700 X-Trace: newsgroups.borland.com 1200430510 207.105.83.66 (15 Jan 2008 12:55:10 -0700) Lines: 80 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail