'===========================================================================
' Subject: GET HARD DISK SERIAL NUMBER        Date: 06-13-99 (07:52)       
'  Author: Leandro Pardini                    Code: QB, QBasic, PDS        
'  Origin: lpardini@navigo.com.ar           Packet: DISK.ABC
'===========================================================================
'Hi there,
'
'I was looking at the ABC site and I found the "Wanted snippets" page.
'one of them was: "Get IDE Hard Drive Serial Number". Well, here it is.
'This thing uses a internal function from DOS 4.0 and beyond to get
'the serial number, disk label and filesystem type. The InfoLevel
'integer is always 0 in DOS.
'
'I think this will work both in QBasic and QuickBasic (I made a version
'with InterruptX but I dropped it since it would work only on QB); but
'there are a few troubles. This doesn't work with disks formatted before
'MS-DOS 4.0 (and most pre-formatted diskettes don't have the required
'BIOS Parameter Block neither). This doesn't work on network drives,
'nor with Novell DOS 7. However it will work perfectly with IDE disks,
'SCSI disks, diskettes, CD-ROMs, CD Audio, and maybe even with ZIP and
'JAZ drives. Just with anything that haves a drive letter, volume label,
'and serial number.
'
'BTW, I'm the same Leandro Pardini from last year's ABC Packets,
'but with a new address (I've got five ISPs in five months). If
'you'd wrote me to lpardini@cefex.com and didn't get any answer,
'try again at lpardini@navigo.com.ar; Cefex is down for good.
'
'Read you all!

TYPE DiskInfo
   InfoLevel AS INTEGER
   Serial AS LONG
   Label AS STRING * 11
   FileSys AS STRING * 8
END TYPE

DECLARE SUB GetDiskInfo (DriveNum AS INTEGER, Parameter AS DiskInfo, ErrCode AS INTEGER)

DIM HardDisk AS DiskInfo
DIM ErrCode AS INTEGER

CLS

COLOR 14: PRINT "Drive", "Serial", "Label", "FileSys"
FOR DiskNum% = 1 TO 20
   GetDiskInfo DiskNum%, HardDisk, ErrCode
   IF ErrCode > 0 THEN
   COLOR 7: PRINT CHR$(DiskNum% + 64); ": - Err:"; ErrCode
   ELSE
   COLOR 15: PRINT CHR$(DiskNum% + 64); ":", HEX$(HardDisk.Serial), HardDisk.Label, HardDisk.FileSys
   END IF
NEXT DiskNum%

SUB GetDiskInfo (DriveNum AS INTEGER, Parameter AS DiskInfo, ErrCode AS INTEGER)
ErrCode = 0
DIM AsmCode AS STRING * 32
MID$(AsmCode, 1, 4) = CHR$(184) + MKI$(VARSEG(Parameter)) + CHR$(142)
MID$(AsmCode, 5, 5) = CHR$(216) + CHR$(184) + CHR$(0) + CHR$(105) + CHR$(187)
MID$(AsmCode, 10, 3) = CHR$(DriveNum) + CHR$(0) + CHR$(186)
MID$(AsmCode, 13, 4) = MKI$(VARPTR(Parameter)) + CHR$(205) + CHR$(33)
MID$(AsmCode, 17, 5) = CHR$(114) + CHR$(1) + CHR$(203) + CHR$(80) + CHR$(184)
MID$(AsmCode, 22, 4) = MKI$(VARSEG(ErrCode)) + CHR$(142) + CHR$(216)
MID$(AsmCode, 26, 4) = CHR$(88) + CHR$(187) + MKI$(VARPTR(ErrCode))
MID$(AsmCode, 30, 3) = CHR$(137) + CHR$(7) + CHR$(203)
DEF SEG = VARSEG(AsmCode)
CALL ABSOLUTE(VARPTR(AsmCode))
DEF SEG
END SUB
