Microsoft KB Archive/62458

= How to Find All Available Logical Drives in Basic =

Article ID: 62458

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 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 Q62458



SUMMARY
A Basic program can call interrupts to find out which logical drives are available. The interrupts used are 21Hex, function 0EHex (Select disk) and 21Hex, function 19Hex (Get current disk). The method involves circulating through each possible logical drive (A-Z) and calling the interrupt to select that drive. If this is successful, subsequently calling the interrupt to get the current drive should return that same drive. If it isn't the same, the drive wasn't successfully selected and therefore isn't available.



MORE INFORMATION
Function 0EH of interrupt 21H (Select disk) requires input from the following registers:   AH (upper byte of AX) = 0EH DL (lower byte of DX) = drive code (0=A, 1=B, etc.) When called, it makes the drive passed in DL current, if possible. If that drive is not available, the interrupt does not return an error. That is why function 19H of interrupt 21H (Get current disk) must be called to see if function 0EH was successful. Function 19H requires the following registers for input:   AH (upper byte of AX) = 19H It returns the following:   AL (lower byte of AX) = current drive code (0=A, 1=B, etc.) For more information on interrupt 21H, functions 0EH and 19H, see Pages 355 and 367 (respectively) of &quot;Advanced MS-DOS Programming, Second Edition,&quot; by Ray Duncan (Microsoft Press, 1988).

The following program displays all the available logical drives: 'Remember to invoke QB.EXE (or QBX.EXE) with the /L switch) because 'support for CALL Interrupt is in QB.QLB (or QBX.QLB).

'$INCLUDE: 'qb.bi'                   'Use 'qbx.bi' for QBX.EXE. DIM Regs AS RegType                  'Holds register values.

PRINT &quot;The following logical drives are available:&quot;;

FOR Drive% = 0 TO 25                 'Circulate through drives A-Z.

Regs.ax = &HE00                   'Function 0EH (AH = 0EH). Regs.dx = Drive% CALL Interrupt(&H21, Regs, Regs)  'Select a drive, if it's there.

Regs.ax = &H1900                  'Function 19H (AH = 19H). CALL Interrupt(&H21, Regs, Regs)  'Get currently selected drive.

IF (Regs.ax AND &HFF) = Drive% THEN '(Regs.ax AND &HFF) = AL.      PRINT &quot; &quot;; CHR$(Drive% + 65);   'If current drive = last drive END IF                            'selected, drive is available.

NEXT Drive%

Additional query words: QuickBas BasicCom

Keywords: KB62458

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.