Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to read MAC address using WMI MSNdis

219 views
Skip to first unread message

Tom K

unread,
Aug 10, 2005, 12:46:04 PM8/10/05
to
I am trying to read a network adapters MAC address using WMI.

A code snippet is below. I query the MSNdis_EthernetCurrentAddress class
to get the address. All is good until I have to use the
MSNdis_NetworkAddress.

I don't know what to do with the value returned by:

hr = object->Get( L"NdisCurrentAddress", 0, &var_val, NULL, NULL );

I know that the return (var_val) is a class of type MSNdis_NetworkAddress.
How do I instantiate/use this class. I am sorry is this is dumb question but
I am new to COM and very new to WMI.

Thanks,

Tom

code snippet start -------->

hr = service->ExecQuery( _bstr_t(L"WQL"), _bstr_t(L"SELECT * FROM
MSNdis_EthernetCurrentAddress"),
WBEM_FLAG_FORWARD_ONLY, NULL, &enumerator );
if ( SUCCEEDED( hr ) )
{
// read the first instance from the enumeration (only one on single
processor machines)
IWbemClassObject* processor = NULL;
ULONG retcnt;
VARIANT var_val;
IWbemClassObject* object = NULL;
while(hr != WBEM_S_NO_MORE_DATA && hr != S_FALSE)
{
hr = enumerator->Next( WBEM_INFINITE, 1L, &object, &retcnt );
if ( SUCCEEDED( hr ) )
{
if ( retcnt > 0 )
{

hr = object->Get( L"InstanceName", 0, &var_val, NULL, NULL );

_bstr_t str = var_val.bstrVal;
std::cerr << str << std::endl;

hr = object->Get( L"NdisCurrentAddress", 0, &var_val, NULL, NULL );
std::cerr << "got something: ";

<--------- code snippet end


Arkady Frenkel

unread,
Aug 16, 2005, 9:26:54 AM8/16/05
to
Try \src\general\wmicli\console from DDK , as example it use
MSNdis_MediaSupported

Arkady

"Tom K" <To...@discussions.microsoft.com> wrote in message
news:0D16608E-DCD0-41FB...@microsoft.com...

Tom K

unread,
Aug 16, 2005, 4:45:05 PM8/16/05
to
Hi Arkady,

I have taken a look at the example but I still do not understand exactly
what steps I must take to get an Instance of class that is a property of
another WMI class.

In my case, the NdisCurrentAddress property of
MSNdis_EthernetCurrentAddress is an instance of MSNdis_NetworkAddress. If I
use IWbemClassObject::Get i will get the property as a VARIANT. I need to
get this property as an instance.

I experimented with the IWbemService::GetObject function but I cannot figure
out how to make it get an instance that is a property of another class.

Thanks, Tom

Arkady Frenkel

unread,
Aug 17, 2005, 5:23:44 AM8/17/05
to
You can't get property as an instance AFAIK , btw you can look at my example
( as origin I used project I mentioned ) :
http://www.ndis.com/faq/Contributors/CheckNet/default.htm

Arkady

"Tom K" <To...@discussions.microsoft.com> wrote in message

news:40CD0274-E3FC-4F09...@microsoft.com...

Gerry Hickman

unread,
Aug 17, 2005, 2:42:31 PM8/17/05
to
Hi,

Looking at some of these examples, it seems that this is using Win API
and DDK as oppose to pure WMI? I can't find anything related to NDIS in
the WMI documentation.

According to the docs, you can get the MAC adddress quite easily from
the Win32_NetworkAdapterConfiguration class.

A more interesting question, is how can you enable/disable a NIC or
change it's speed using pure WMI?

Arkady Frenkel wrote:


--
Gerry Hickman (London UK)

Arkady Frenkel

unread,
Aug 18, 2005, 4:22:45 AM8/18/05
to
Hi!
"Gerry Hickman" <gerry...@yahoo.co.uk> wrote in message
news:u7q6Mt1o...@TK2MSFTNGP12.phx.gbl...

> Hi,
>
> Looking at some of these examples, it seems that this is using Win API and
> DDK as oppose to pure WMI? I can't find anything related to NDIS in the
> WMI documentation.
>
Do you mean script ?
WMI really is COM object so what you see is real COM based of C ( even not
C++ ) .It have two parts : one is user mode service and second wmilib.sys -
driver ( kernel ) part

> According to the docs, you can get the MAC adddress quite easily from the
> Win32_NetworkAdapterConfiguration class.
>
> A more interesting question, is how can you enable/disable a NIC or change
> it's speed using pure WMI?

As API that enable or devcon examples from DDK for first and if driver
support setting of speed by OID ( OID_GEN_LINK_SPEED ) that can be done ,
otherwise -no
Arkady

Gerry Hickman

unread,
Aug 18, 2005, 8:46:16 AM8/18/05
to
Hi Arkady,

>>DDK as oppose to pure WMI?

> Do you mean script ?


> WMI really is COM object so what you see is real COM based of C ( even not
> C++ ) .It have two parts : one is user mode service and second wmilib.sys -
> driver ( kernel ) part

No, I don't mean script. I mean I can't find the MSNDIS classes
documented anywhere in the WMI documentation on MSDN, in fact I can't
them documented ANYWHERE on Microsoft's site! The crazy thing, is that I
can connect to root\wmi and enum the class thanks to

<http://www.ndis.com/faq/QA01050301/default.htm>

Pavel A.

unread,
Aug 19, 2005, 7:37:18 PM8/19/05
to
"Gerry Hickman" <gerry...@yahoo.co.uk> wrote in message news:u7q6Mt1o...@TK2MSFTNGP12.phx.gbl...
> I can't find anything related to NDIS in the WMI documentation.

Aha. So I am not alone ...

> According to the docs, you can get the MAC adddress quite easily from the Win32_NetworkAdapterConfiguration class.

Yes, the quick way is vbscript or wmic.

> A more interesting question, is how can you enable/disable a NIC or change it's speed using pure WMI?

No. There is no WMI object that can enable or disable physical device, including NIC.
If you really want it... write it yourself.

Changing the link speed in runtime is impossible, because the link speed OID is read only.
You need to change the speed parameter in the registry, and then (see above)
disable the NIC and re-enable it.
Unfortunately this parameter will have standard names and values only in Vista,
currently only the NIC vendors know how to set it.

Regards,
--PA


Arkady Frenkel

unread,
Aug 22, 2005, 4:58:36 AM8/22/05
to
The only description is mof files , that really never appeared in docs :(
Arkady

"Gerry Hickman" <gerry...@yahoo.co.uk> wrote in message

news:%23ktEzK$oFHA...@TK2MSFTNGP12.phx.gbl...

rkr...@gmail.com

unread,
Aug 25, 2005, 2:21:49 PM8/25/05
to
Hey Tom,

Did you ever figure out the issue of having a VARIANT and needing it to
be an IWbemClassObject?

I'm running in to the same thing trying to get the
MSNdis_EthernetPermanentAddress.

Rod

Mike M.

unread,
Oct 6, 2005, 8:30:49 AM10/6/05
to
Here is the answer:

Here's the snippet once we have the NdisPermanentAddress object in a
variant pVal.

IWbemClassObject *pNetworkAddress;
hres = pVal.punkVal->QueryInterface( IID_IWbemClassObject,
(PVOID *) &pNetworkAddress);
BSTR addressName = SysAllocString(L"Address");
VARIANT pAddress;
VariantClear(&pAddress);
hres = pNetworkAddress->Get(addressName, 0L, &pAddress, NULL, NULL);
pNetworkAddress->Release();

char permAddress[6];
for (long index = 0; index < 6; index++) {
SafeArrayGetElement(pAddress.parray, &index, &permAddress[index]);
}

<rkr...@gmail.com> wrote in message
news:1124994109.2...@f14g2000cwb.googlegroups.com...

0 new messages