Basic Can Obtain MS-DOS Disk Serial Number for Floppy Drive (82156)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q82156

SUMMARY

The following code example demonstrates how to retrieve the disk serial number from an MS-DOS formatted floppy disk. (Disks formatted by MS-DOS versions 4.0 and later receive a serial number). The example uses Interrupt 25 hex to do an absolute disk read of the first sector on the disk (the boot sector). After the sector has been read into memory, the disk serial number can be found at offsets 28 hex, 29 hex, 2a hex, and 2b hex of that memory area.

MORE INFORMATION

The code example below is written for Microsoft Basic PDS versions 7.0 or 7.1. The code can easily be modified to work with QuickBasic 4.0, 4.0b, or 4.5 by following the directions in the remarked statements.

Note: The following program example will work only with floppy disk drives (for example: drive A or drive B). This program example will NOT work properly with hard drives.
' $INCLUDE: 'qbx.bi'
'use QB.BI include file for QuickBasic 4.0 and 4.5
MemBuffer$ = SPACE$(512) 'Buffered area for sector read
                         'Buffer = 512 bytes = size of sector
DIM inregs  AS RegTypeX
DIM outregs AS RegTypeX

inregs.ax = 0            '0=Drive A, 1=Drive B
inregs.cx = 1            'number of sectors to read
inregs.dx = 0            'starting sector location

'For QuickBasic 4.0 and 4.5, add the following remarked line:
'inregs.ds = VARSEG(MemBuffer$)
inregs.ds = SSEG(MemBuffer$)    'MemBuffer$'s segment address
inregs.bx = SADD(MemBuffer$)    'MemBuffer$'s offset
CALL InterruptX(&H25, inregs, outregs)
LowBytes% = CVI(MID$(MemBuffer$, &H28, 2)) 'Offset 27h in boot sector
HighBytes% = CVI(MID$(MemBuffer$, &H2A, 2))'Offset 29h in boot sector
PRINT "Serial Number - "; HEX$(HighBytes%); "-"; HEX$(LowBytes%)
				

REFERENCES

"The New Peter Norton Programmer's Guide to The IBM PC & PS/2," Peter Norton, Microsoft Press, 1988

"Advanced MS-DOS Programming," Ray Duncan, Microsoft Press, 1988

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB82156