[bb] Drive Volume Information by EOF [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Drive Volume Information
Author : EOF
Posted : 1+ years ago

Description : This returns lots of handy info regarding volume information.

Please test and let me know if it reports the right details!

Now you can find out:
Volume Name          My Computer etc ...
Type                 Fixed, Floppy ,CD-Rom etc
Serial Number        Device serial number
Flags                Don't know much about these yet
File System          FAT32, NTFS, CDFS, ...
Format               0 or 255 (indicates short (8.3) or long format)


Note1: Throw the declarations into 'Kernel32.decls'
Note2: There is a small delay when checking Floppy Drives. [/i]

Code :
Code (blitzbasic) Select
; Volume Information

; !!   place these in 'Kernel32.decls'   !!
; *****************************************
; GetDriveType%(drivename$):"GetDriveTypeA"
; GetVolumeInformation%(Path$,VolNameBuff*,VolLen%,Serial*,MaxComponentLen*,fsFlags*,fsNameBuff*,fsNameLen%):"GetVolumeInformationA"
; GetLogicalDriveStrings%(bufflen%,buffer*):"GetLogicalDriveStringsA"
; *****************************************



; volume details are stored here
Type volumeinfo
Field driveletter$     ; Drives letter                "A:"  "C:"   "F:"
Field drivename$       ; Name of device               "My Computer"
Field drivetype$       ; What type                    "Floppy" "CD-Rom"
Field serial%          ; Serial number                1234567890
Field maxcomponentlen% ; long/short name support      8.3  255
Field flags%           ; associated flags             012345
Field filesystem$      ; file system used             FAT32 NTFS CDFS
End Type
Global vol.volumeinfo

GetVolumeInfo ; fill 'volumeinfo' type with available volumes information

Print "Vol     Name                Type          Serial       Flags    FileSystem"
Print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
For vol=Each volumeinfo
r$=voldriveletter$+"     "+Left$(voldrivename$+String$(" ",19),19)
r$=r$+" "+Left$(voldrivetype$+String$(" ",12),12)
r$=r$+" "+Right$(String$(" ",10)+Str$(volserial),11)+"   "
r$=r$+Right$("      "+Str$(volflags),6)+"   "+volfilesystem
Print r$
Next

Print
a$=Input$("Done ... RETURN to end")
End



Function GetVolumeInfo()
; first, get a list of available volumes  .. A:B:C:F: ...
vlist=CreateBank(256)
GetLogicalDriveStrings 255,vlist
drivelist$=PeekString$(vlist,256)
FreeBank vlist
; run through list of voulumes
For x=0 To Len(drivelist$)/3-1
vol=New volumeinfo
voldriveletter$=Mid$(drivelist$,x*3+1,3)
voldrivename$="(not available)"
Select GetDriveType(voldriveletter$)
Case 2 : voldrivetype$= "Removable"
Case 3 : voldrivetype$= "Drive Fixed"
Case 4 : voldrivetype$= "Remote"
Case 5 : voldrivetype$= "Cd-Rom"
Case 6 : voldrivetype$= "Ram disk"
Default : voldrivetype$= "Unrecognized"
End Select
vn=CreateBank(256) : sn=CreateBank(4)
mcl=CreateBank(4) : flags=CreateBank(4) : fs=CreateBank(256)
GetVolumeInformation voldriveletter$,vn,255,sn,mcl,flags,fs,255
voldrivename$=PeekString$(vn,256)
If voldrivename$="" Then voldrivename$="(not available)"
volserial=PeekInt(sn,0)
volmaxcomponentlen=PeekInt(mcl,0)
volflags=PeekInt(flags,0)
volfilesystem=PeekString$(fs,256)
; free the banks
FreeBank sn : FreeBank mcl : FreeBank flags
FreeBank vn : FreeBank fs
Next
End Function

; build and return a string of characters from a bank
Function PeekString$(bank,numbytes)
Local a$=""
For pos=0 To numbytes-1
byte=PeekByte(bank,pos)
If byte<>0 Then a$=a$+Chr$(byte)
Next
Return a$
End Function


Comments :


David Boudreau(Posted 1+ years ago)

 For BlitzPlus- In the middle of this code, join the first 2 lines of:Printa$=Input$("Done ... RETURN to end")Endto:Print a$=Input$("Done ...Return to end")Endor, at least in BlitzPlus, you need to do this.