获取MAC地址:#include "stdafx.h"
#include "mac.h"//using namespace std;bool GetAdapterInfo(int nAdapterNum, char sMAC[C_MAC_LEN])
{
    // Reset the LAN adapter so that we can begin querying it 
    NCB Ncb;
    memset(&Ncb, 0, sizeof(Ncb));
    Ncb.ncb_command = NCBRESET;
    Ncb.ncb_lana_num = nAdapterNum;
    if (Netbios(&Ncb) != NRC_GOODRET)
{
        _snprintf(sMAC,C_MAC_LEN,"r:0x%02X",Ncb.ncb_retcode);
        return false;
    }
    
    // Prepare to get the adapter status block 
    memset(&Ncb, 0, sizeof(Ncb));
    Ncb.ncb_command = NCBASTAT;
    Ncb.ncb_lana_num = nAdapterNum;
    strcpy((char *) Ncb.ncb_callname, "*");
    struct ASTAT {
        ADAPTER_STATUS adapt;
        NAME_BUFFER NameBuff[30];
    } Adapter;
    memset(&Adapter, 0, sizeof(Adapter));
    Ncb.ncb_buffer = (unsigned char *)&Adapter;
    Ncb.ncb_length = sizeof(Adapter);
    
    // Get the adapter's info and, if this works, return it in standard,
    // colon-delimited form.
    if (Netbios(&Ncb) == 0) {
        char acMAC[18];
        sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
                int (Adapter.adapt.adapter_address[0]),
                int (Adapter.adapt.adapter_address[1]),
                int (Adapter.adapt.adapter_address[2]),
                int (Adapter.adapt.adapter_address[3]),
                int (Adapter.adapt.adapter_address[4]),
                int (Adapter.adapt.adapter_address[5]));
        memcpy(sMAC,acMAC,C_MAC_LEN);
sMAC[C_MAC_LEN] = 0;
        return true;
    }
    else {
        
_snprintf(sMAC,C_MAC_LEN,"a:0x%02X",Ncb.ncb_retcode);
        return false;
    }
}

解决方案 »

  1.   

    获取磁盘序列号:
    #include "stdafx.h"
    #include "volserial.h"BOOL GetVolumeSerialNumber (LPCSTR pszRootPathName, DWORD *pdwSerialNum)
    {
       BOOL bReturn = FALSE;  // Assume that we haven't get the serial number,
                              // then set it to true if we do get it.   HANDLE hFile;
       BY_HANDLE_FILE_INFORMATION bhFileInfo;   HANDLE          hFileFind;
       WIN32_FIND_DATA wfdFileData;
       char            szFindFileName[MAX_PATH];
       /*
          Search for any file that we can open and retrieve information about.
          That information will include the serial number of the volume on
          which the file resides.
       */ 
       lstrcpy (szFindFileName, pszRootPathName);
       lstrcat (szFindFileName, "*");   hFileFind = FindFirstFile (szFindFileName, &wfdFileData);
       if (INVALID_HANDLE_VALUE == hFileFind)
          goto EXIT_DONE;   do
       {
          /* Make sure that we've found a file and not a directory */ 
          if (!(wfdFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
          {
             /*
                Found a file.  Now, use the full path to open the file and get
                information about it. This information includes the serial
                number of the volume on which the file resides.  If we do get
                the info, we can bail out because we're done.            If we can't open this file, look for another one we can open.
             */ 
             lstrcpy (szFindFileName+lstrlen(pszRootPathName),
                      wfdFileData.cFileName);         hFile = CreateFile (szFindFileName,
                                 0,    // don't need to open for read or write
                                 FILE_SHARE_READ|FILE_SHARE_WRITE,
                                 NULL, OPEN_EXISTING, 0, NULL);
             if (INVALID_HANDLE_VALUE != hFile)
             {
                bReturn = GetFileInformationByHandle(hFile, &bhFileInfo);
                CloseHandle(hFile);            if (bReturn)
                   break;
             }
          }
       }
       while (FindNextFile(hFileFind, &wfdFileData));
       CloseHandle (hFileFind);  /* don't need the find handle anymore */    /* If we have the serial number, return it to the caller */ 
       if (bReturn )
       {
          __try
          {
             *pdwSerialNum = bhFileInfo.dwVolumeSerialNumber;
          }
          __except (EXCEPTION_EXECUTE_HANDLER)
          {
             SetLastError (ERROR_INVALID_PARAMETER);
             bReturn = FALSE;
          }
       }EXIT_DONE:
       return (bReturn);
    }
      

  2.   

    这位老哥做 VC 的 跑Java 区来干嘛??? 不过很感谢...解决的问题