I've tried using some tools to get hardware information in DOS, but they did not have source code for free use. I need a code solution that returns me the serial number or ID in the MS-DOS environment.
I've tried using some tools to get hardware information in DOS, but they did not have source code for free use. I need a code solution that returns me the serial number or ID in the MS-DOS environment.
You can dir
and get output
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// O prefixo do 'dir' que identifica o serial number
#define SNPREFIX " Volume Serial Number is "
// MUDAR AQUI ----^^^^^^^^^^^^^^^^^^^^^^^^^
int main(void) {
char line[512];
FILE *process;
process = popen("cmd /c dir c:", "r");
// MUDAR AQUI --------------^
while (fgets(line, sizeof line, process)) {
line[strlen(line) - 1] = 0; // clear ENTER
if (strncmp(line, SNPREFIX, strlen(SNPREFIX)) == 0) {
printf("==> %s <==\n", line + strlen(SNPREFIX));
}
}
return 0;
}
Output on my machine (in your case you have to change the "c:" to the letter that is associated with the pen drive)
==> 8662-7ACB <==
From what I understand, what you are looking for is this:
wmic diskdrive get PNPDeviceID
Or:
wmic diskdrive get SerialNumber
Source: link