CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2003
    Posts
    87

    Question Bios Program using C++

    Hi

    I want to write a program that lists the computers specifications from Bios. I dont know where to begin with this project. I dont know how to implement such a program.

    It must be a popular type of program to write.

    Thanks in advance for your help.

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Legacy methods and Windows registry

    Mike,

    If you have access to a ancient version of MSVC1.52 or earlier (from 1993) then there was a legacy function called _bios_equiplist(...). We used to use this function to read stuff for DOS applications. This development environment is no longer readily available and WinNT/2000/XP will not even allow this function due to direct read of secured memory addresses.

    There is a modern way to read this information from the Windows registry. Below is another technique using the Windows registry. This is an older program that I wrote years ago in plain-C and it has some stylistic problems. Nevertheless, the function calls are important. The example shows some queries about the CPU characteristics.

    Other gurus will certainly know how to do this better. There are many wrapper-classes available as free-ware for reading the registry.

    Sincerely, Chris.



    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    
    // This is an old legacy C-function for reading the Windows registry
    // sections related to the central processing unit.
    static BOOL QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(BYTE* abyOut, const char* pstrIn, DWORD dwSize)
    {
      const char strHKEY_CPU[] =
               "Hardware\\Description\\System\\CentralProcessor\\0";
    
      auto  LONG  lResult  = 0;
    
      // Use statics since address passing to subroutine will be used.
      static  HKEY    hKey;
      static  DWORD   dwDataSize;
      static  BYTE    abyData[1024];
    
      BOOL bOK = FALSE;
    
      // Initialize variables
      dwDataSize = dwSize;
      memset((void*) abyData, 0, sizeof(abyData));
    
      // Get the CPU information
      lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                             strHKEY_CPU,
                             0,
                             KEY_READ,
                             &hKey);
    
      if(lResult == ERROR_SUCCESS)
      {
        // Query desired registry value.
        lResult = RegQueryValueEx(hKey,
                                  pstrIn,
                                  NULL,
                                  NULL,
                                  abyData,
                                  &dwDataSize);
    
        if(lResult == ERROR_SUCCESS)
        {
          memcpy(abyOut, abyData, dwDataSize * sizeof(BYTE));
          bOK = TRUE;
        }
      }
    
      // Make sure to close the reg key
      RegCloseKey(hKey);
    
      return bOK;
    }
    
    int main(int argc, char* argv[])
    {
      BYTE data[128];
    
      // Read CPU Frequency
      ::memset(data, 0, 128 * sizeof(BYTE));
      ::QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(data,
                                                        "~MHz",
                                                        sizeof(DWORD));
    
      DWORD dw_MHz = *(reinterpret_cast<DWORD*>(&data[0]));
    
      ::std::cout << "CPU Frequency [MHz]: " << dw_MHz << ::std::endl;
    
      // Test for genuine Intel
      ::memset(data, 0, 128 * sizeof(BYTE));
      ::QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(data,
                                                        "VendorIdentifier",
                                                        sizeof("GenuineIntel"));
    
      if(::std::string(reinterpret_cast<char*>(data)) == ::std::string("GenuineIntel"))
      {
        ::std::cout << "Is genuine Intel!" << ::std::endl;
      }
    
      return 1;
    }
    Last edited by dude_1967; March 16th, 2003 at 05:50 AM.
    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    Feb 2003
    Posts
    87
    dude_1967 when I run your program I get an output saying that my machine is running at 0mhz!

    I am using Windows XP Proffesional.

    I compiled your program using Visual C++
    6.

  4. #4
    Join Date
    Sep 2002
    Posts
    1,747
    This older thread will give you a start on getting information directly from the bios if that is your goal. The reason dude_1967's program gives the wrong display is the use of bytes instead of dwords to hold the result, but the idea of using the registry is quite sound, and much of the machine's configuration can be found there.
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  5. #5
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Mike,
    galathaea,

    This program ran for me under Win2000 yesterday when I posted it. I did not have a chance to run it on XP. I still believe that the program, although stylistically less than optimal, should run.

    For some reason yesterday I had problems with the posting of the code. I noticed that the format of the page inserted a blank character in the fixed string

    Code:
    const char strHKEY_CPU[] =
               "Hardware\\Description\\System\\CentralProcessor\\0";
    The post shows a blank at the start of the string. However there should be no blank.

    I tried to post the code as an attatchment but could not figure out how to push the buttons.

    Anyway the post by galathaea should be a better place to start.


    Sincerely, Chris.

    You're gonna go blind staring into that box all day.

  6. #6
    Join Date
    Sep 2002
    Posts
    1,747
    I completely missed the reinterpret_cast's type when I first read the program posted by dude_1967. I read it wrong, and apologize for the error in my association of that with the error. I have seen some blank insertions by the forum software a couple of times too, and wish I understood what was triggering it...
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured