Ricevere informazioni su un Drive e controllare se un CD è inserito.
Come ricevere alcune informazioni su un Drive, incluse il nome ed il numero seriale del Volume. Puoi ricevere anche informazioni circa il tipo di drive (hard disk, cdrom, rimovibile, etc.)
Aggiungi il seguente codice in un modulo:
Option Explicit
Public 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
Public Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Const DRIVE_CDROM = 5
Aggiungi un CommandButton in un Form con il seguente codice:
Option Explicit
Private Sub Command1_Click()
Dim VName As String, FSys As String, erg As Long
Dim NSerial As Long
Dim Drive As String, DriveType As Long
VName = String$(255, Chr$(0))
FSys = String$(255, Chr$(0))
'Inserisci la lettera del drive che desideri
Drive = "f:\"
DriveType = GetDriveType(Drive)
erg = GetVolumeInformation(Drive, VName, 255, _
NSerial, 0, 0, FSys, 255)
VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
FSys = Left$(FSys, InStr(1, FSys, Chr$(0)) - 1)
Cls
Print "Nome Volume:" & vbTab & VName
Print "Numero Seriale:" & vbTab & NSerial
Print "FileSystem:" & vbTab & FSys
Print "Tipo di Drive:" & vbTab & DriveType;
'Il drive è un CDROM?.Se è cosi, cerca per un CD
If DriveType = DRIVE_CDROM Then
Print " (CDROM, ";
If erg = 0 Then
Print "nessun CD nel drive)"
Else
Print "CD presente nel drive)"
End If
Else
Print " (NON E' CDROM)"
End If
End Sub
Testato su: Windows 98, Windows Me, Windows
2000 Professional