Reputation:
How to get the unique number (serial number/ID) for Processor (CPU), SCSI, Display, and IDE using C++ program other than WMI and asm code?
Upvotes: 1
Views: 10531
Reputation: 4520
The below is the code I use to retrieve the hard drive serial for a game, so that cheaters are permanently banned (and they can't get back in without getting a new drive!):
string GetMachineID()
{
// LPCTSTR szHD = "C:\\"; // ERROR
string ss;
ss = "Err_StringIsNull";
UCHAR szFileSys[255],
szVolNameBuff[255];
DWORD dwSerial;
DWORD dwMFL;
DWORD dwSysFlags;
int error = 0;
bool success = GetVolumeInformation(LPCTSTR("C:\\"), (LPTSTR)szVolNameBuff,
255, &dwSerial,
&dwMFL, &dwSysFlags,
(LPTSTR)szFileSys,
255);
if (!success) {
ss = "Err_Not_Elevated";
}
std::stringstream errorStream;
errorStream << dwSerial;
return string(errorStream.str().c_str());
}
Although there is a potential bug whereupon if Windows is installed onto a drive other than C:\
, this is an easy fix.
Upvotes: 1
Reputation:
On Windows you can get CPU info from the environment variable *PROCESSOR_** , you can parse the volume serial number from vol, the MAC address from route print
If you want to make it cross-platform (and if this is for software licensing) then an open source platform like Linux raises the problem to a whole new level anyway and requires a different approach. However you can still get a lot of the info by parsing the output from standard tools.
You really should consider WMI. In the old days, the BIOS would have been helpful but its all been replaced by the HAL.
CodeProject is always worth searching in cases like this.
How To Get Hardware Information
Upvotes: 1
Reputation: 14138
Since you mention WMI, I assume you are working on Windows. Lookup GetVolumeInformation().
Upvotes: 3