例如windows 设备管理中的 Realtek RTL8139 Family PCI Fast Ethernet NIC,都研究两天了,还是没解决啊:(

解决方案 »

  1.   

    我早都关注这个帖子了,正在搜索MSDNing...
      

  2.   

    NdisMQueryAdapterInstanceName retrieves the friendly name of a physical NIC or a virtual adapter. 
    NDIS_STATUS
      NdisMQueryAdapterInstanceName(
        OUT PNDIS_STRING  AdapterInstanceName,
        IN NDIS_HANDLE  MiniportAdapterHandle
        );http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/NdisXMd_Mz_a20f1c3a-afb9-46e2-9c3c-19432a94716a.xml.asp
      

  3.   

    从MSDN中查到,NdisMQueryAdapterInstanceName应该可以得到你需要的。
      

  4.   

    利用注册表,vc.net测试通过#include "stdafx.h"
    #include <windows.h>
    #include <atlstr.h>
    #include <assert.h>int _tmain(int argc, _TCHAR* argv[])
    {
    HKEY hKey;
    CString strSubKeyName = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards");
    if ( ERROR_SUCCESS != ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKeyName, 0, KEY_ALL_ACCESS, &hKey) )
    {
    printf("没有网卡\n");
    }// end of if
    LONG RetCode = 0;
    for( int i=0; ; i++ )
    {
    CString strEnumedSubKey;
    TCHAR str[200];
    DWORD dw = 200;
    if( ERROR_SUCCESS != RegEnumKeyEx(hKey,i,str,&dw,NULL,NULL,NULL,NULL))
    {
    break;
    }
    strEnumedSubKey = strSubKeyName + CString(_T("\\") + CString(str)); HKEY hNetCardKey;
    assert( ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,strEnumedSubKey,0,KEY_ALL_ACCESS,&hNetCardKey));

    DWORD cbdw = 1000;
    BYTE bDate[1000];
    DWORD valType = REG_SZ;
    if( ERROR_SUCCESS == ::RegQueryValueEx(hNetCardKey,_T("Description"),NULL,&valType,(LPBYTE)bDate,&cbdw))
    {
    printf("第%d块网卡:%s\n",i+1,CString(bDate));
    }
    }// end of for return 0;
    }
      

  5.   

    那我不在windows下运行怎么办啊?
      

  6.   

    晕,不是windows环境你跑到vc版问?
      

  7.   

    楼主,为了你这个帖子,许多朋友今天都来找我,结果你居然不是windows环境!ft
      

  8.   

    不好意思,我实在是找不到地方问了,去了C里面问了,可是没什么人能回答阿,可能是大家都比较忙吧.我在网上搜索的有利用DeviceIoControl CreateFile GUID HANDLE 等的,但是总是没调通。
    在windows下也行,但是我怕windows的版太多了,不能稳定运行阿(网卡在注册表里面的路径),希望大家在帮我看看,再次感谢大家!
      

  9.   

    不好意思,我实在是找不到地方问了,去了C里面问了,可是没什么人能回答阿,可能是大家都比较忙吧.我在网上搜索的有利用DeviceIoControl CreateFile GUID HANDLE 等的,但是总是没调通。
    在windows下也行,但是我怕windows的版太多了,不能稳定运行阿(网卡在注册表里面的路径),希望大家在帮我看看,再次感谢大家!
      

  10.   

    楼主呀,你…………你……我就不说了,vc++不在windows下运行,你把它安装到哪里?
      

  11.   

    我们软件需要用户选择网卡,目前可以只考虑在windows这种环境下。我们是想获得网卡的名称和带宽信息。
    目前,我们获得的网卡名称像这样:“NDIS 5.0   ”(这是从WinPCap中获得的)。这样可读性太差了。
    我们希望获得如这样的显示:“Realtek RTL8139 Family PCI Fast Ethernet NIC”。
    还有就是获得网卡的带宽:如是10M的还是100M的等。如果是自适应的我们想获得当前的带宽是多少。通过大家的指教,我想从注册表中获得显卡名称是没问题了,但是怎样获得带宽呢?此外,除了读注册表,我们尝试使用CreateFile()获得网卡的句柄,然后用DeviceIOControl()获得网卡的相关信息,但没有尝试成功,不知道这种方法行不行。
      

  12.   

    NT系列的操作系统可以用WMI获得
    // Get WMI information.
    //tested by onega VC20003,windows 2003
    #include "stdafx.h"
    #define _WIN32_DCOM
    #include <iostream>
    using namespace std;
    #include <comdef.h>
    #include <Wbemidl.h>
    #include <atlcomcli.h>
    # pragma comment(lib, "wbemuuid.lib")
    struct InitOle
    {
    InitOle()  

    hres = CoInitializeEx(0, COINIT_MULTITHREADED);
    }
    ~InitOle() { ::CoUninitialize();  }
    HRESULT hres;
    } _init_InitOle_;
    HRESULT PrintObject(IWbemClassObject* spInstance)
    {
    if(!spInstance)
    return S_OK;
    std::cout<<__FUNCTION__<<" start "<<std::endl;
    LPSAFEARRAY psa = NULL;
    HRESULT hres;
    hres = spInstance->GetNames(   NULL,
    WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY,
    NULL,
    &psa);
    long   lLower, lUpper;
    SafeArrayGetLBound(psa , 1, &lLower);
    SafeArrayGetUBound(psa , 1, &lUpper);
    for (long i = lLower; i <= lUpper; ++i) 
    {
    CComBSTR   bstrPropName;
    if (S_OK !=  (hres = SafeArrayGetElement(psa, &i, &bstrPropName)) )
    {
    if (NULL != psa)
    SafeArrayDestroy(psa);
    return hres;
    }
    //if(bstrPropName!="name")
    // continue;
    std::cout<<"  "<<(LPCTSTR)_bstr_t(bstrPropName);
    _variant_t varProperty;
    HRESULT hr = spInstance->Get(bstrPropName,0,&varProperty,NULL,0);
    std::cout<<" = ";
    if(varProperty.vt !=VT_EMPTY && VT_NULL != varProperty.vt)
    {
    _variant_t vDest;
    hr = VariantChangeType(&vDest, &varProperty,0,VT_BSTR);
    if(SUCCEEDED(hr))
    std::cout<< (LPCTSTR)_bstr_t(varProperty);
    else
    {
    if(varProperty.vt == (VT_ARRAY|VT_I4))
    {
    SAFEARRAY* psa = varProperty.parray;
    int *pIntArray = NULL;
    SafeArrayAccessData(psa,(VOID**)&pIntArray);
    UINT uDim = SafeArrayGetDim(psa);
    if(1==uDim)
    {
    long lLbound,lRbound;
    SafeArrayGetLBound(psa,1,&lLbound);
    SafeArrayGetUBound(psa,1,&lRbound);
    for(long i=lLbound;i<=lRbound;i++)
    {
    std::cout<< pIntArray[i]<<" ";
    }
    }
    SafeArrayUnaccessData(psa);
    }
    else
    {
    std::cout<< varProperty.vt << " type ";
    }
    }
    }
    else
    {
    if(varProperty.vt == VT_EMPTY)
    std::cout<< "VT_EMPTY ";
    else
    std::cout<< "VT_NULL";
    }
    std::cout<<std::endl;
    }
    if (NULL != psa)
    SafeArrayDestroy(psa);
    std::cout<<__FUNCTION__<<" end "<<std::endl;
    return S_OK;
    }int get_wmi_info(CComPtr<IWbemServices>& pSvc,_bstr_t classname)
    {
    // Step 6: --------------------------------------------------
    // Use the IWbemServices pointer to make requests of WMI ----
    _bstr_t wmi_query_str("SELECT * FROM ");
    wmi_query_str +=classname;
    CComPtr<IEnumWbemClassObject> pEnumerator;//IEnumWbemClassObject* pEnumerator = NULL;
    HRESULT hres = pSvc->ExecQuery(
    bstr_t("WQL"), 
    wmi_query_str,
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
    NULL,
    &pEnumerator);
    if (FAILED(hres))
    {
    cout << "Query for "<<(LPCSTR)classname<<" failed."
    << " Error code = 0x" 
    << hex << hres << endl;
    return 1;               // Program has failed.
    }
    // Step 7: -------------------------------------------------
    // Get the data from the query in step 6 -------------------
    ULONG uReturn = 0;
    while (pEnumerator)
    {
    CComPtr<IWbemClassObject> pclsObj;//IWbemClassObject *pclsObj;
    HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
    &pclsObj, &uReturn);
    if(0 == uReturn)
    {
    break;
    }
    PrintObject(pclsObj);
    }
    return 0;
    }
    int main(int argc, char **argv)
    {
    HRESULT hres = S_OK;
    if (FAILED(_init_InitOle_.hres))
    {
    cout << "Failed to initialize COM library. Error code = 0x" 
    << hex << hres << endl;
    return 1;                  // Program has failed.
    }
    // Step 2: --------------------------------------------------
    // Set general COM security levels --------------------------
    // Note: If you are using Windows 2000, you need to specify -
    // the default authentication credentials for a user by using
    // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
    // parameter of CoInitializeSecurity ------------------------ hres =  CoInitializeSecurity(
    NULL, 
    -1,                          // COM authentication
    NULL,                        // Authentication services
    NULL,                        // Reserved
    RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
    RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
    NULL,                        // Authentication info
    EOAC_NONE,                   // Additional capabilities 
    NULL                         // Reserved
    );
    if (FAILED(hres))
    {
    cout << "Failed to initialize security. Error code = 0x" 
    << hex << hres << endl;
    return 1;                    // Program has failed.
    }
    // Step 3: ---------------------------------------------------
    // Obtain the initial locator to WMI -------------------------
    CComPtr<IWbemLocator> pLoc;//IWbemLocator *pLoc = NULL;
    hres = CoCreateInstance(
    CLSID_WbemLocator,             
    0, 
    CLSCTX_INPROC_SERVER, 
    IID_IWbemLocator, (LPVOID *) &pLoc);
    if (FAILED(hres))
    {
    cout << "Failed to create IWbemLocator object."
    << " Err code = 0x"
    << hex << hres << endl;
    return 1;                 // Program has failed.
    }
    // Step 4: -----------------------------------------------------
    // Connect to WMI through the IWbemLocator::ConnectServer method
    CComPtr<IWbemServices> pSvc;//IWbemServices *pSvc = NULL;
    // Connect to the root\cimv2 namespace with
    // the current user and obtain pointer pSvc
    // to make IWbemServices calls.
    hres = pLoc->ConnectServer(
    _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
    NULL,                    // User name. NULL = current user
    NULL,                    // User password. NULL = current
    0,                       // Locale. NULL indicates current             
    NULL,                    // Security flags.
    0,                       // Authority (e.g. Kerberos)        
    0,                       // Context object 
    &pSvc                    // pointer to IWbemServices proxy
    ); if (FAILED(hres))
    {
    cout << "Could not connect. Error code = 0x" 
    << hex << hres << endl;
    return 1;                // Program has failed.
    }
    cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
    // Step 5: --------------------------------------------------
    // Set security levels on the proxy -------------------------
    hres = CoSetProxyBlanket(
    pSvc,                        // Indicates the proxy to set
    RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
    RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
    NULL,                        // Server principal name 
    RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
    RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
    NULL,                        // client identity
    EOAC_NONE                    // proxy capabilities 
    );
    if (FAILED(hres))
    {
    cout << "Could not set proxy blanket. Error code = 0x" 
    << hex << hres << endl;
    return 1;               // Program has failed.
    }
    get_wmi_info(pSvc,"Win32_NetworkAdapter");
    return 0;   // Program successfully completed.
    }
      

  13.   

    ft,在这的都些什么人啊?!
    MSDN,查GetAdaptersInfo函数
    或用SetupApi函数