🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #714

Re: WMI Network unplugged

#714
From: JohnG
Date: Tue, 15 Jan 2008 13:35
48 lines
2444 bytes
>        TInitOle ole; // constructor calls CoInitialize/Ex()
Thank you for that piece of advice!!

I have modified a portion of the code so that it correctly
detects the connections status of the specified nic. All that is left if to modify this code to allow me use WMI to monitor events.

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->ExecQuery( WideString("WQL"),
						WideString("select * from Win32_NetworkAdapter Where Description = \"Intel(R) PRO/1000 MT Network Connection\" And NetConnectionStatus = 0"),							WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
		NULL,
                &pEnumerator);

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

IWbemClassObject *pclsObj;
ULONG uReturn = 0;

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

   if(0 == uReturn)
   {
      break;
   }

   VARIANT vtProp; 
   // Get the value of the Name property
   hr = pclsObj->Get(WideString("NetConnectionStatus"),
                     0, &vtProp, 0, 0);

   //add code to check connection
   VariantClear(&vtProp);
}
Technical Details
Message-ID: <478cc4b9$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <478b8203$1@newsgroups.borland.com> <478ba4ea$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,382c3d02983b6dd6
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: Re: WMI Network unplugged
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 138.11.0.153     
X-Forwarded-For: unknown
References: <478b8203$1@newsgroups.borland.com> <478ba4ea$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <478cc4b9$1@newsgroups.borland.com>
Date: 15 Jan 2008 06:35:37 -0700
X-Trace: newsgroups.borland.com 1200407737 207.105.83.66 (15 Jan 2008 06:35:37 -0700)
Lines: 48
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail