Obtaining BIOS data


#1

Hi All,

does anybody knows how to obtain BIOS data (especially the Serial Number) on both Windows (32 and 64 bit) and Mac?

Cheers!
Emanuele


#2

I surfed on the Internet and I found these:

http://www.codeproject.com/KB/system/SMBIOS_Peek.aspx

http://developer.apple.com/library/mac/#technotes/tn1103/_index.html

Does anybody has tried them?
I’m going to do some test…


#3

First successful test: this is working for me on Mac OS X 10.7.2

#include <iostream>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>


// Returns the serial number as a CFString. 
// It is the caller's responsibility to release the returned CFString when done with it.
std::string CopySerialNumber()
{
	CFStringEncoding encoding = kCFStringEncodingMacRoman;
	std::string result; 
	
	io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
															  IOServiceMatching("IOPlatformExpertDevice"));
	
	if (platformExpert)
	{
		CFStringRef serialNumberAsCFString = (CFStringRef)
		IORegistryEntryCreateCFProperty(platformExpert,
										CFSTR(kIOPlatformSerialNumberKey),
										kCFAllocatorDefault, 0);
		
		if (serialNumberAsCFString)
		{
			result = CFStringGetCStringPtr(serialNumberAsCFString, encoding);
		}
		
		IOObjectRelease(platformExpert);
	}
	
	return result;
}


int main (int argc, char * const argv[]) {
	
	std::string serialnumber = CopySerialNumber();
	
	
	std::cout << serialnumber << "\n";
	return 0;
	
}