Microsoft KB Archive/82156

= Basic Can Obtain MS-DOS Disk Serial Number for Floppy Drive =

Article ID: 82156

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 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 &quot;Serial Number - &quot;; HEX$(HighBytes%); &quot;-&quot;; HEX$(LowBytes%)

