Microsoft KB Archive/84482

= Basic Program to Change Floppy Disk Volume Label in MS-DOS =

Article ID: 84482

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q84482



SUMMARY
The following code example demonstrates how to retrieve and modify the volume label from an MS-DOS formatted floppy disk. (Disks formatted by MS-DOS versions 4.0 and later receive an optional volume label in the boot sector of the disk). 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 volume label can be found and modified at offsets 2C hex to 37 hex of that memory area. The sector is then rewritten to the disk using Interrupt 26 hex (Absolute Disk Write).

This information applies to Microsoft QuickBasic versions 4.0, 4.0b, and 4.5 for MS-DOS; Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; and Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS.



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 or Basic Compiler 6.0 or 6.0b 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.

WARNING: This example uses Interrupt 25 hex and 26 hex to read and write the boot sector of a floppy drive. You must use caution while implementing the routine below. Improper use can result in permanent disk damage. Microsoft is not responsible for any damage, lost work, or lost time that may be caused by this example. ' $INCLUDE: 'QBX.BI' 'use QB.BI include file for QuickBasic 4.0 and 4.5, instead of QBX.BI

MemBuffer$ = SPACE$(512) 'Buffered area for sector read 'Buffer = 512 bytes = size of sector on                        '                     floppy drives DIM NewVol AS STRING * 11 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 or write inregs.dx = 0           'starting sector location

'Read the Sector into MemBuffer From Disk using Interrupt 25 hex '(Absolute Disk Write) 'For QuickBasic 4.0 and 4.5, replace the line of code 'inregs.ds = SSEG(MemBuffer$) 'with the code: inregs.ds = VARSEG(MemBuffer$) inregs.ds = SSEG(MemBuffer$)   'MemBuffer$'s segment address inregs.bx = SADD(MemBuffer$)   'MemBuffer$'s offset CALL InterruptX(&H25, inregs, outregs)  'Read Sector 0 (Absolute Disk                                         'Read) inregs.ax = 0           '0=Drive A, 1=Drive B inregs.cx = 1            'number of sectors to read or write inregs.dx = 0           'starting sector location

PRINT &quot;The Current Label Is: &quot;; MID$ (MemBuffer$, &H2C, 11) INPUT &quot;Enter The New Volume Label (11 characters or less): &quot;; NewVol

'Modify the Sector, MemBuffer$, with new label selection MID$ (MemBuffer$, &H2C, 11) = MID$ (NewVol, 1, 11)

'Write the MemBuffer back to the Disk using Interrupt 26 hex '(Absolute Disk Write) 'For QuickBasic 4.0 and 4.5, replace the line of code 'inregs.ds = SSEG(MemBuffer$) 'with the code: inregs.ds = VARSEG(MemBuffer$) inregs.ds = SSEG(MemBuffer$)   'MemBuffer$'s segment address inregs.bx = SADD(MemBuffer$)   'MemBuffer$'s offset CALL InterruptX(&H26, inregs, outregs)    'Write Sector 0 '(Absolute Disk Write)

