checking HD's volume serial number

checking HD's volume serial number

Post by Yan » Wed, 07 Mar 2001 11:44:48

deal all,

does anyone know how to check the hard disk's volume serial number (e.g.
4227-19E1) with c/c++?



checking HD's volume serial number

Post by Anthony Borl » Wed, 07 Mar 2001 14:30:11

Quote:> deal all,

> does anyone know how to check the hard disk's volume serial number (e.g.
> 4227-19E1) with c/c++?

The following is for a 16 bit DOS executable. Compiled using Borland 5.0,
and works ok under DOS, Win9x and NT 4.0.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* DOS Disk Volume Data Structure */
typedef struct
  unsigned int reserved;
  unsigned int serial_low;
  unsigned int serial_high;
  unsigned char volume[11];
  unsigned char FAT[8];

Quote:} VolumeData;

/* Prototypes */
VolumeData* getVolumeData(unsigned char drvno);
unsigned char* getDiskSerial(unsigned char drvno);

/* Driver */
int main()
  /* Get Disk Serial Number */
  printf("Disk Serial No: %s\n", getDiskSerial('C')); fflush(stdout);

  return EXIT_SUCCESS;


/* Helper Function, actually issues DOS interrupt to obtain
   disk volume data
VolumeData* getVolumeData(unsigned char drvno)
  static VolumeData volumeData;

  unsigned char ok = 0;

    mov ax, 6900H

    xor bx, bx
    mov bl, drv

    lea dx, volumeData

    int 21H

    jc EXIT

    mov ok, 01H


  if (!ok) return NULL;

  return &volumeData;


/* Disk Serial Number */
unsigned char* getDiskSerial(unsigned char drvno)
  VolumeData* vptr;
  static unsigned char serial[20] = {'\0'};

  if ((vptr = getVolumeData(drvno)) == NULL)
    return NULL;

  sprintf(serial, "%04X-%04X", vptr->serial_high, vptr->serial_low);

  return serial;


The following is for a Win32 executable. Compiled using Borland 5.5, and
works ok under Win9x and NT 4.0.

// Standard Headers
#include <iostream>
#include <cstdio>

// Non-standard Headers
#include <windows.h>

// Driver
int main()
  unsigned long serial; char serialBuffer[20];

  if (!GetVolumeInformation("C:\\", NULL, NULL, &serial, NULL, NULL, NULL,
    std::cout << "Error getting Disk Serial Number" << std::endl;
    std::sprintf(serialBuffer, "%4.4X-%4.4X", HIWORD(serial),
    std::cout << "Serial: " << serialBuffer << std::endl;

  return 0;



1. How does VOL get the "Volume Serial Number" of a HD?

Hi there,
   I have a question about both DOS and PC hardware:
   1. Does every reasonably sized hard disk (>=40Mg) have a "Volume Serial
      Number" as reported by the DOS command VOL?
   2. How could I retrieve this datum, say in 'C', without parsing VOL's
Help would be greatly appreciated (direct to my e-mail box, please)

2. Expert settings: Glidepoint

3. how read the HD's serial number

4. Picture Windows

5. How to calculate the HD volume number?

6. $150 - HP PCMCIA 10/20c FlashCard

7. GNU toolchain

8. How do I change the Volume Serial Num on my HD ??

9. Volume Serial Number - How to change it?

10. Reading Volume Serial Numbers in C

11. Volume Serial Number

12. Changing "Volume Serial Number" (Microsoft OSes) ...