dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: BIOS Serial (Code Included)

  1. #16
    Join Date
    Apr 2005
    Posts
    42

    Re: BIOS Serial (Code Included)

    I have been getting mails to provide the whole code for reading Motherboard serial, so following are the header and source files for Visual C++.NET.

    Header file:
    #ifndef BIOS_H
    #define BIOS_H
    #using <mscorlib.dll>

    #include "stdafx.h"
    #define _WIN32_DCOM
    #include <iostream>
    #include <comdef.h>
    #include <Wbemidl.h>

    namespace MotherBoard
    {
    using namespace std;
    class BIOS{
    public:
    _bstr_t RetrieveBIOSInfo();
    private:
    };
    }
    #endif


    Source File:
    #include "stdafx.h"
    #include "bios.h"
    #using <mscorlib.dll>



    # pragma comment(lib, "wbemuuid.lib")


    _COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator));
    _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
    _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
    _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject));

    using namespace MotherBoard;
    _bstr_t BIOS::RetrieveBIOSInfo()
    {
    _bstr_t bios;
    HRESULT hres = S_OK;
    // Initialize COM.
    hres = CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }

    // Initialize
    hres = CoInitializeSecurity(
    NULL,
    -1, // COM negotiates service
    NULL, // Authentication services
    NULL, // Reserved
    RPC_C_AUTHN_LEVEL_DEFAULT, // authentication
    RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation
    NULL, // Authentication info
    EOAC_NONE, // Additional capabilities
    NULL // Reserved
    );


    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }

    // Obtain the initial locator to Windows Management
    // on a particular host computer.
    IWbemLocatorPtr spLoc = NULL;

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

    if (FAILED(hres))
    {
    bios.operator =('none'); //Program has failed
    }

    IWbemServicesPtr spSvc = NULL;

    // Connect to the root\cimv2 namespace with the
    // current user and obtain pointer pSvc
    // to make IWbemServices calls.

    hres = spLoc->ConnectServer(

    _bstr_t(L"ROOT\\CIMV2"), // WMI namespace
    NULL, // User name
    NULL, // User password
    0, // Locale
    NULL, // Security flags
    0, // Authority
    0, // Context object
    &spSvc // IWbemServices proxy
    );

    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }

    cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;

    // Set the IWbemServices proxy so that impersonation
    // of the user (client) occurs.
    hres = CoSetProxyBlanket(

    spSvc, // the proxy to set
    RPC_C_AUTHN_WINNT, // authentication service
    RPC_C_AUTHZ_NONE, // authorization service
    NULL, // Server principal name
    RPC_C_AUTHN_LEVEL_CALL, // authentication level
    RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
    NULL, // client identity
    EOAC_NONE // proxy capabilities
    );

    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }
    IWbemClassObjectPtr spBaseBoard = NULL;
    if( FAILED( hres = spSvc->GetObject(_bstr_t("Win32_BaseBoard.Tag=\"Base Board\""),
    0,
    NULL,
    &spBaseBoard,
    NULL)) )
    {
    bios.operator =('none');
    }

    variant_t v;
    if( FAILED( hres = spBaseBoard->Get(bstr_t( L"SerialNumber" ), 0, &v, 0, 0)) )
    {
    bios.operator =('none');
    }
    bios = bstr_t(v);
    return bios;
    }

  2. #17
    Join Date
    Apr 2005
    Posts
    42

    Re: BIOS Serial (Code Included)

    u can get the BIOS serial by changing the WMI class of Motherboard mentioned in the code to BIOS class in WMI (see that in MSDN)

  3. #18
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Re: BIOS Serial (Code Included)

    Please, when post source code, include it between &#91;CODE&#93; and &#91;/CODE&#93; tags to make it readable.
    Last edited by ovidiucucu; November 19th, 2005 at 06:49 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #19
    Join Date
    Apr 2005
    Posts
    42

    Resolved Re: BIOS Serial (Code Included)

    I have been getting mails to provide the whole code for reading Motherboard serial, so following are the header and source files for Visual C++.NET.

    Header file:
    Code:
    #ifndef BIOS_H
    #define BIOS_H
    #using <mscorlib.dll>
    
    #include "stdafx.h"
    #define _WIN32_DCOM
    #include <iostream>
    #include <comdef.h>
    #include <Wbemidl.h>
    
    namespace MotherBoard 
    {
    using namespace std;
    class BIOS{
    public:
    _bstr_t RetrieveBIOSInfo();
    private:
    };
    }
    #endif
    Source File:
    Code:
    #include "stdafx.h"
    #include "bios.h"
    #using <mscorlib.dll>
    
    
    
    # pragma comment(lib, "wbemuuid.lib")
    
    
    _COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator));
    _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
    _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
    _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject));
    
    using namespace MotherBoard;
    _bstr_t BIOS::RetrieveBIOSInfo()
    {
    _bstr_t bios;
    HRESULT hres = S_OK;
    // Initialize COM.
    hres = CoInitializeEx(0, COINIT_MULTITHREADED); 
    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }
    
    // Initialize 
    hres = CoInitializeSecurity(
    NULL, 
    -1, // COM negotiates service 
    NULL, // Authentication services
    NULL, // Reserved
    RPC_C_AUTHN_LEVEL_DEFAULT, // authentication
    RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation
    NULL, // Authentication info 
    EOAC_NONE, // Additional capabilities
    NULL // Reserved
    );
    
    
    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }
    
    // Obtain the initial locator to Windows Management
    // on a particular host computer.
    IWbemLocatorPtr spLoc = NULL;
    
    hres = CoCreateInstance(
    CLSID_WbemLocator, 
    0, 
    CLSCTX_INPROC_SERVER, 
    IID_IWbemLocator, (LPVOID *) &spLoc);
    
    if (FAILED(hres))
    {
    bios.operator =('none'); //Program has failed
    }
    
    IWbemServicesPtr spSvc = NULL;
    
    // Connect to the root\cimv2 namespace with the
    // current user and obtain pointer pSvc
    // to make IWbemServices calls.
    
    hres = spLoc->ConnectServer(
    
    _bstr_t(L"ROOT\\CIMV2"), // WMI namespace
    NULL, // User name
    NULL, // User password
    0, // Locale
    NULL, // Security flags 
    0, // Authority 
    0, // Context object
    &spSvc // IWbemServices proxy
    ); 
    
    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed.
    }
    
    cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
    
    // Set the IWbemServices proxy so that impersonation
    // of the user (client) occurs.
    hres = CoSetProxyBlanket(
    
    spSvc, // the proxy to set
    RPC_C_AUTHN_WINNT, // authentication service
    RPC_C_AUTHZ_NONE, // authorization service
    NULL, // Server principal name
    RPC_C_AUTHN_LEVEL_CALL, // authentication level
    RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
    NULL, // client identity 
    EOAC_NONE // proxy capabilities 
    );
    
    if (FAILED(hres))
    {
    bios.operator =('none'); // Program has failed. 
    } 
    IWbemClassObjectPtr spBaseBoard = NULL;
    if( FAILED( hres = spSvc->GetObject(_bstr_t("Win32_BaseBoard.Tag=\"Base Board\""),
    0,
    NULL,
    &spBaseBoard,
    NULL)) )
    {
    bios.operator =('none');
    }
    
    variant_t v;
    if( FAILED( hres = spBaseBoard->Get(bstr_t( L"SerialNumber" ), 0, &v, 0, 0)) )
    {
    bios.operator =('none');
    }
    bios = bstr_t(v);
    return bios;
    }

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)