This tip
demonstrates how you can receive lots of
information about a drive, including the
Volume name and number. You can also
retrieve information about the type of
drive (hard disk, cdrom, removable, etc.)
Module Code:
Add the following code to
a module:
Declare Function GetVolumeInformation
Lib _
"kernel32" Alias
"GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Declare Function GetDriveType Lib "kernel32"
_
Alias "GetDriveTypeA" (ByVal nDrive As
String) As Long
Public Const DRIVE_CDROM = 5
Form Code:
Add one command button to a form with the
following code:
Private Sub Command1_Click()
Dim VolName As String, FSys As String, erg As Long
Dim VolNumber As Long, MCM As Long, FSF As Long
Dim Drive As String, DriveType As Long
VolName = Space(127)
FSys = Space(127)
Drive = "F:\" 'Enter the driverletter you
want
DriveType& = GetDriveType(Drive$)
erg& = GetVolumeInformation(Drive$, VolName$,
127&, _
VolNumber&, MCM&, FSF&, FSys$, 127&)
Print "VolumeName:" & vbTab &
VolName$
Print "VolumeNumber:" & vbTab &
VolNumber&
Print "MCM:" & vbTab & vbTab &
MCM&
Print "FSF:" & vbTab & vbTab &
FSF&
Print "FileSystem:" & vbTab & FSys$
Print "DriveType:" & vbTab &
DriveType&;
'Is the drive a CDROM, if so, check for a CD
If DriveType& = DRIVE_CDROM Then
Print " (CDROM, ";
If erg& = 0 Then
Print "no CD in the
drive)"
Else
Print "CD in the drive)"
End If
Else
Print " (NO CDROM)"
End If
End Sub
|