得到网络管理中心显示的网卡

#include “StdAfx.h”
#include<atlstr.h>
#include <NetCon.h>
#include <stdlib.h>
int main()
{
long lCardNum = 0;
TCHAR szServiceName[6][256];
CString strServiceName;
CString strGuidId ;
IEnumNetConnection *pEnum = NULL;
INetConnectionManager *pManager = NULL;
INetConnection *pConnection = NULL;
ULONG celt = 0;
NETCON_PROPERTIES *Nproperties = NULL;
INetSharingManager *pNetSharingManager = NULL;
INetSharingConfiguration *pConfiguration = NULL;

    //可用なネットワークアダプタの接続状態を取得します。
CoInitialize(NULL);
CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_SERVER, IID_INetConnectionManager, (void**)&pManager);
if(pManager == NULL)
{
    printf("異常、失敗,Error:%d\n",GetLastError());
    return 1;
}
pManager->EnumConnections(NCME_DEFAULT, &pEnum);
while(pEnum->Next(1, &pConnection, &celt) == S_OK )
{
    pConnection->GetProperties(&Nproperties);
    strGuidId.Format(_T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}" )
                    ,Nproperties->guidId.Data1 
                    ,Nproperties->guidId.Data2 
                    ,Nproperties->guidId.Data3 
                    ,Nproperties->guidId.Data4[0]
                    ,Nproperties->guidId.Data4[1] 
                    ,Nproperties->guidId.Data4[2]
                    ,Nproperties->guidId.Data4[3]
                    ,Nproperties->guidId.Data4[4]
                    ,Nproperties->guidId.Data4[5] 
                    ,Nproperties->guidId.Data4[6]
                    ,Nproperties->guidId.Data4[7]
                    ); 


        strServiceName = strGuidId ;
        printf("strServiceName = %S \n",(LPCTSTR)strServiceName);
}
if(pManager)           pManager->Release();
if(pConnection)        pConnection->Release();
if(pEnum)              pEnum->Release();
if(pNetSharingManager) pNetSharingManager->Release();
if(pConfiguration)     pConfiguration->Release();
CoUninitialize();

system("pause");
return 0;

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注