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

Asked

Viewed 1,876 times

1

I have tried using some tools to get hardware information on DOS, but they did not have the source code for free use. I need a code solution that returns the serial number or ID in the MS-DOS environment.

  • I am using MS-DOS 7.10 and DJGPP as compiler.

2 answers

1

You can do dir and pick up the 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 associated with the pen drive)

==> 8662-7ACB <==

0

  • WMIC came with windows 2000 if I’m not mistaken. DOS 7.1 is from the 95 season, at most 98.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.