2014-09-15 5 views
0

C++을 사용하여 로컬 시스템의 BIOS에서 자산 태그 및 일련 번호를 얻는 방법을 배우고 싶습니다. 나는 지금 거의 한시간 동안 온라인으로 검색을 해왔고, 지금까지 내가 가진 모든 것은 VB에서 작성된 몇 개의 스크립트이다.C++을 사용하여 바이오스에서 자산 태그 및 일련 번호 가져 오기

저는 Windows 7 컴퓨터에서 작업하고 있지만 Windows 8에서도 작동하고 싶습니다.

답변

0

당신은 내가 PC의 일련 번호를 얻기 위해 함께 넣어 다음 소스 같은 것 WMI

예 기능을 사용할 수 있으며, 그것은 매우 잘 작동하는 것 같다. Windows 레지스트리에서 일련 번호를 가져 오는 것은 실패했지만, 특수한 환경의 경우처럼 무시됩니다.

# pragma comment(lib, "wbemuuid.lib") 
static SHORT CDeviceConfigCheckSerialNumber (TCHAR *tcsSerialNo) 
{ 
    HRESULT hres; 
    IWbemLocator *pLoc = NULL; 

    *tcsSerialNo = 0; // initialze return string to empty string 

    hres = CoCreateInstance(
     CLSID_WbemLocator,    
     0, 
     CLSCTX_INPROC_SERVER, 
     IID_IWbemLocator, (LPVOID *) &pLoc); 

    if (FAILED(hres)) 
    { 
     return 1;     // Program has failed. 
    } 

    // Step 4: ----------------------------------------------------- 
    // Connect to WMI through the IWbemLocator::ConnectServer method 

    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 (for example, Kerberos) 
     0,      // Context object 
     &pSvc     // pointer to IWbemServices proxy 
     ); 

    if (FAILED(hres)) 
    { 
     pLoc->Release();  
     return 2;    // Program has failed. 
    } 

    // 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)) 
    { 
     pSvc->Release(); 
     pLoc->Release();  
     return 3;    // Program has failed. 
    } 

    // Step 6: -------------------------------------------------- 
    // Use the IWbemServices pointer to make requests of WMI ---- 

    // For example, get the name of the operating system 
    IEnumWbemClassObject* pEnumerator = NULL; 
    hres = pSvc->ExecQuery(
     bstr_t("WQL"), 
//  bstr_t("SELECT * FROM Win32_SystemEnclosure"), 
//  bstr_t("SELECT * FROM Win32_BaseBoard"), 
     bstr_t("SELECT * FROM Win32_BIOS"), 
     WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
     NULL, 
     &pEnumerator); 

    if (FAILED(hres)) 
    { 
     pSvc->Release(); 
     pLoc->Release(); 
     return 4;    // Program has failed. 
    } 

    // Step 7: ------------------------------------------------- 
    // Get the data from the query in step 6 ------------------- 

    IWbemClassObject *pclsObj; 
    ULONG uReturn = 0; 

    SHORT sRetStatus = -100; 

    while (pEnumerator) 
    { 
     HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); 

     if(0 == uReturn) 
     { 
      break; 
     } 

     VARIANT vtProp; 

     // Get the value of the Name property 
     hr = pclsObj->Get(L"SerialNumber", 0, &vtProp, 0, 0); 
     if (!FAILED(hres)) { 
      switch (vtProp.vt) { 
       case VT_BSTR: 
        _tcscpy (tcsSerialNo, vtProp.bstrVal); 
        sRetStatus = 0; 
        break; 
      } 
     } 
     VariantClear(&vtProp); 

     pclsObj->Release(); 
    } 
    pEnumerator->Release(); 

    // Cleanup 
    // ======== 
    pSvc->Release(); 
    pLoc->Release(); 

    // if the search for a serial number in the BIOS did not provide 
    // something then lets see if the NCR Retail Systems Manager has 
    // put a serial number into the Windows Registry. 
    if (sRetStatus != 0) { 
     ULONG ulCount = 0; 
     TCHAR lpszValue[256] = {0}; 

     ScfGetRsmValue (L"SerialNumber", &ulCount, lpszValue); 
     if (ulCount > 0) { 
      _tcscpy (tcsSerialNo, lpszValue); 
      sRetStatus = 0; 
     } 
    } 
    return sRetStatus; 
}