I'm trying to find a way to capture the HD serial, CPU and motherboard, the CPU I found a way that is using cpuid.h, now the motherboard and the HD I did not find way to capture power, someone Do you have any ideas?
I'm trying to find a way to capture the HD serial, CPU and motherboard, the CPU I found a way that is using cpuid.h, now the motherboard and the HD I did not find way to capture power, someone Do you have any ideas?
There are a few ways to do this. You can use the system
command in c
to call a terminal command directly.
system("hdparm -i /dev/hda | grep -i serial");
static struct hd_driveid hd;
int fd;
if ((fd = open("/dev/hda", O_RDONLY | O_NONBLOCK)) < 0) {
printf("ERROR opening /dev/hda\n");
exit(1);
}
if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) {
printf("%.20s\n", hd.serial_no);
} else if (errno == -ENOMSG) {
printf("No serial number available\n");
} else {
perror("ERROR: HDIO_GET_IDENTITY");
exit(1);
}
system("wmic path win32_physicalmedia get SerialNumber");
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT SerialNumber FROM Win32_PhysicalMedia"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
hr = pclsObj->Get(L"SerialNumber", 0, &vtProp, 0, 0);
Solution removed from SOen .