Windows WMI - 获取多个MAC地址

时间:2014-05-19 09:24:41

标签: c++ c windows wmi mac-address

我正在使用以下函数和查询来检索网络适配器的MAC地址:

QueryValue( pService, L"SELECT MACAddress FROM Win32_NetworkAdapter", L"MACAddress", NetMacAddress, bufferLength );

但我不知道如何指定我想要获取地址的卡。有没有办法使用WMI获取计算机上每张卡的MAC地址(假设它们被激活,所有这些)?或者使用其他东西?

谢谢:)

1 个答案:

答案 0 :(得分:1)

如果没有WMI,你可以简单地使用这样的东西......

unsigned long ulLen = 0;
    IP_ADAPTER_ADDRESSES* p_adapAddress = NULL;

    DWORD dwRetValue = GetAdaptersAddresses(AF_INET, 0, NULL, p_adapAddress,&ulLen);
    if(dwRetValue == ERROR_BUFFER_OVERFLOW)
    {
        p_adapAddress = (PIP_ADAPTER_ADDRESSES)malloc(ulLen);
        if(p_adapAddress)
        {
            dwRetValue = GetAdaptersAddresses(AF_INET, 0, NULL, p_adapAddress,&ulLen);
            if(dwRetValue == NO_ERROR)
            {                                                   
                IP_ADAPTER_ADDRESSES* p_adapAddressAux = p_adapAddress;
                do
                {
                    // Get the value of the p_adapAddressAux.PhysicalAddress

                }
                while(p_adapAddressAux != NULL);                                                    
            }

            free(p_adapAddress);
        }
    }