Click to See Complete Forum and Search --> : Bios Program using C++
mikebaily
March 15th, 2003, 02:51 PM
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.
dude_1967
March 16th, 2003, 04:24 AM
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.
:)
#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;
}
mikebaily
March 16th, 2003, 12:45 PM
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.
galathaea
March 16th, 2003, 07:08 PM
This older thread (http://www.codeguru.com/forum/showthread.php?s=&threadid=229170&highlight=bios) 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.
dude_1967
March 17th, 2003, 04:10 AM
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
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.
:)
galathaea
March 17th, 2003, 07:42 AM
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...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.