Re: determine volume serial number
- Posted by David Cuny <dcuny at DSS.CA.GOV> Jan 02, 1998
- 744 views
I've run across the information requested in BASIC, but am too stupid to make th e translation: --- START OF FILE ------------------------ ' DISKID.BAS reports disk volume and serial number from boot sector ' ' Author: Christy Gemmell (christy.gemmell at almac.co.uk) ' Date: 12/4/1992 ' ' Captured from alt.lang.basic newsgroup on July 20, 1995 and converted ' to PowerBASIC by Dave Navarro, Jr. (dave at powerbasic.com) TYPE ParaBlock Info AS INTEGER ' Call information level SerNo AS LONG ' Disk serial number Label AS STRING * 11 ' Volume label FlSys AS STRING * 8 ' File system type END TYPE INPUT "Which drive - <Enter> for default"; D$ GetDiskID D$, S$, V$, F$ PRINT PRINT "Disk information for drive "; D$ PRINT "----------------------------" PRINT "Volume label : "; V$ PRINT "Serial number : "; S$ PRINT "File system : "; F$ END SUB GetDiskID (Drive$, Serial$, Volume$, FileSys$) DIM Para AS ParaBlock ' Buffer for drive parameter block Para.Info = 0 ' Information level always zero REG 1, &H440D ' Generic IOCTL device request IF Drive$ = "" THEN ' If no drive specified REG 2, 0 ' then use default ELSE ' Otherwise convert REG 2, ASC(UCASE$(Drive$)) - 64 ' drive letter to number END IF ' A: = 1, B: = 2 etc REG 3, &H866 ' Subfunction: get drive ID REG 8, VARSEG(Para) ' Segment of buffer REG 4, VARPTR(para) ' Offset of buffer CALL INTERRUPT &H21 ' Invoke DOS Serial$ = HEX$(Para.SerNo) ' Get serial number Volume$ = Para.Label ' Get volume label FileSy$ = Para.FlSys ' Get file system type END SUB --- END OF FILE ------------------------ Here's a version that does a DIR command. Note that it only has minimal error ch ecking: --- START OF FILE ------------------------ include file.e function read_serial( sequence from ) -- read the serial number from a given disk integer handle sequence text -- do a DIR command and dump it to a file system( "dir " & from & " > junk.tmp", 2 ) -- open the file handle = open( "junk.tmp", "r" ) -- success? if sequence( dir("junk.tmp") ) then -- skip the blank line text = gets( handle ) -- skip the volume name text = gets( handle ) -- read volume serial number text = gets( handle ) -- slice off the preceeding text text = text[26..length(text)] -- close the file close( handle ) -- delete the temp file system( "del junk.tmp > NUL", 2 ) end if return text end function -- try it out puts( 1, read_serial( "c:" ) ) --- END OF FILE ------------------------ -- David Cuny