How to capture hardware id

2

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?

    
asked by anonymous 18.04.2015 / 04:12

1 answer

1

There are a few ways to do this. You can use the system command in c to call a terminal command directly.

For Linux:

system("hdparm -i /dev/hda | grep -i serial");

Without using system:

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);
}

For Windows:

system("wmic path win32_physicalmedia get SerialNumber");

Without using system (Based on Getting WMI Data ):

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 .

    
18.04.2015 / 06:11