How to get the serial number or ID of a USB stick on the MS-DOS system?

1

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.

    
asked by anonymous 14.03.2016 / 21:50

2 answers

1

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 <==
    
29.03.2016 / 11:51
0

From what I understand, what you are looking for is this:

wmic diskdrive get PNPDeviceID

Or:

wmic diskdrive get SerialNumber

Source: link

    
29.03.2016 / 04:01