Drive Info

- Alyce Alyce Jan 16, 2006
Code copyright 2006 -- Alyce Watson.
Feel free to use it in your own programs. Please give credit to the author. Please do not modify this page. If you have comments or suggestions about this code, click the discussion link at the top of the page.

Thanks. - Alyce Alyce

'Drives$ contains the installed drives when a program
'starts running. It is not refilled if drives are
'added or removed while a program is running.
'
'Use the following API method during a program's run
'to discover which drives are installed at any particular
'time.

print "Drives$ holds this information: ";Drives$
print:print
 
'set up a small string buffer:
driveString$ = space$(2)
lenBuffer = len(driveString$)
 
'make the API call to find out how big the buffer must be
calldll #kernel32, "GetLogicalDriveStringsA",_
lenBuffer as ulong,_   'length of buffer
driveString$ as ptr,_  'string buffer will be filled by function
numBytes as ulong      'returns the needed size of buffer

'resize buffer to hold the returned information:
driveString$ = space$(numBytes+1)
lenBuffer = len(driveString$)
 
'make the call again to fill the buffer with drive info
calldll #kernel32, "GetLogicalDriveStringsA",_
lenBuffer as ulong,_   'length of buffer
driveString$ as ptr,_  'string buffer will be filled by function
numBytes as ulong      'length of the string returned

'the driveString$ now contains a list of drives,
'separated by null characters
d$ = left$(driveString$,numBytes)
print "API-returned driveString$ is ";chr$(34);d$;chr$(34)
print:print
 
'now break into individual drive info:
print "Current drives on this machine are as follows:"
print
i = 1   'start with first drive in string
while word$(d$,i)<>""
    print word$(d$,i)
    i = i + 1
wend
 
print:print "End of drive listing."
 
end